crypt_tool/
lib.rs

1mod binary_converter;
2mod cipher;
3mod rng;
4
5pub use binary_converter::BytesBitsConverter;
6pub use cipher::XorCipher;
7pub use rng::{simple_random, system_random, LCG};
8
9pub struct CryptConverter {
10    xor_cipher: XorCipher,
11    bytes_bits_converter: BytesBitsConverter,
12}
13
14impl CryptConverter {
15    pub fn new(pwd: &[u8]) -> Self {
16        Self {
17            xor_cipher: XorCipher::new(pwd),
18            bytes_bits_converter: BytesBitsConverter::new(),
19        }
20    }
21
22    pub fn encode(&self, bytes: &[u8]) -> Vec<u8> {
23        self.bytes_bits_converter
24            .bytes_to_bits(&self.xor_cipher.encode(bytes))
25    }
26
27    pub fn decode(&self, bits: &[u8]) -> Vec<u8> {
28        self.xor_cipher
29            .decode(&self.bytes_bits_converter.bits_to_bytes(bits))
30    }
31}