Crates.io | CryptTool |
lib.rs | CryptTool |
version | 0.1.4 |
source | src |
created_at | 2024-10-20 08:38:02.653243 |
updated_at | 2024-11-20 08:54:15.722841 |
description | A versatile and efficient cryptography library implemented in Rust |
homepage | |
repository | https://github.com/guofei9987/CryptTool |
max_upload_size | |
id | 1416060 |
size | 31,745 |
Source Code: https://github.com/guofei9987/CryptTool
This project is a Tool Box about:
This project is mainly used in https://github.com/guofei9987/hidden_watermark_rs
or other projects.
use crypt_tool::{system_random, BytesBitsConverter, LCG, XorCipher};
fn example_random() {
let rand = system_random();
println!("A random number = {}", rand);
let seed = b"a seed";
let mut rnd = LCG::from_seed(seed);
let rand2 = rnd.generate_u8();
println!("Another random number from seed {}", rand2);
let random_str = rnd.generate_random_string(20);
println!("A random String = {}", random_str);
}
fn example_cipher() {
let cipher = XorCipher::new("password1".as_bytes());
let data = vec![0, 255, 128, 64, 32, 16, 8, 4, 2, 1];
let encoded = cipher.encode(&data);
let decoded = cipher.decode(&encoded);
assert_eq!(data, decoded);
}
fn example_data_bin_conversion() {
let converter = BytesBitsConverter::new();
let bytes = vec![0, 1, 2, 255];
let bits = vec![
0, 0, 0, 0, 0, 0, 0, 0, // 0
0, 0, 0, 0, 0, 0, 0, 1, // 1
0, 0, 0, 0, 0, 0, 1, 0, // 2
1, 1, 1, 1, 1, 1, 1, 1, // 255
];
assert_eq!(converter.bytes_to_bits(&bytes), bits);
assert_eq!(converter.bits_to_bytes(&bits), bytes);
}
fn main() {
example_random();
example_cipher();
example_data_bin_conversion();
}