Finish challenge 25 and update License

This commit is contained in:
2022-08-14 12:01:51 -04:00
parent 5158c16d56
commit 1eb76f52b1
7 changed files with 75 additions and 33 deletions

View File

@@ -1,13 +1,6 @@
use crate::bytes::Bytes;
use crate::cbc;
use openssl::symm;
fn xor(a: &Vec<u8>, b: &Vec<u8>) -> Vec<u8> {
Iterator::zip(a.iter(), b.iter())
.map(|z| *(z.0) ^ *(z.1))
.collect()
}
pub fn encrypt(key: &Bytes, nonce: u64, data: &Bytes) -> Bytes {
decrypt(key, nonce, data)
}
@@ -20,8 +13,8 @@ pub fn decrypt(Bytes(key): &Bytes, nonce: u64, Bytes(data): &Bytes) -> Bytes {
for cipher in data.chunks(block_size) {
let mut keyinput = nonce.to_le_bytes().to_vec();
keyinput.append(&mut counter.to_le_bytes().to_vec());
let keystream = cbc::enrypt_aes_128_ecb_block(key, &keyinput);
let mut data = xor(&keystream, &cipher.to_vec());
let keystream = crate::cbc::enrypt_aes_128_ecb_block(key, &keyinput);
let mut data = crate::utils::xor(&keystream, &cipher.to_vec());
result.append(&mut data);
counter += 1;
}