pub fn encryption_oracle(
    b: &[u8],
    r: u8, // for test mocking
) -> Result<Vec<u8>, symmetriccipher::SymmetricCipherError> {
    let mut key = [0 as u8; 16]; // 128 bit key
    generate_key(&mut key);

    let mut ps: Vec<u8> = Vec::new();
    ps.resize(rand::thread_rng().gen_range(5, 11), 0x0);

    generate_key(&mut ps);

    let mut plaintext = ps.clone();

    plaintext.extend_from_slice(b);
    plaintext.extend_from_slice(&ps);

    if r % 2 == 1 {
        return crate::aes_ecb::encrypt_aes_128_ecb(&plaintext, &key);
    }

    let mut iv = [0 as u8; 16];
    generate_key(&mut iv);

    return crate::aes_cbc::encrypt_aes_128_cbc(&plaintext, &key, &iv);
}
/// encryption_oracle
/// 
///  Solution for problem 3 from set 2: <https://cryptopals.com/sets/2/challenges/11>
encryption_oracle
Solution for problem 3 from set 2.
encryption_oracle Solution for problem 3 from set 2 .
pub fn encryption_oracle(
    b: &[u8],
    r: u8, // for test mocking
) -> Result<Vec<u8>, symmetriccipher::SymmetricCipherError> {
    let mut key = [0 as u8; 16]; // 128 bit key
    generate_key(&mut key);
    let mut ps: Vec<u8> = Vec::new();
    ps.resize(rand::thread_rng().gen_range(5, 11), 0x0);
    generate_key(&mut ps);
    let mut plaintext = ps.clone();
    plaintext.extend_from_slice(b);
    plaintext.extend_from_slice(&ps);
    if r % 2 == 1 {
        return crate::aes_ecb::encrypt_aes_128_ecb(&plaintext, &key);
    }
    let mut iv = [0 as u8; 16];
    generate_key(&mut iv);
    return crate::aes_cbc::encrypt_aes_128_cbc(&plaintext, &key, &iv);
}
pub fn encryption_oracle ( b : & [ u8 ] , r : u8 , // for test mocking ) -> Result < Vec < u8 > , symmetriccipher :: SymmetricCipherError > { let mut key = [ 0 as u8 ; 16 ] ; // 128 bit key generate_key ( & mut key ) ; let mut ps : Vec < u8 > = Vec :: new ( ) ; ps . resize ( rand :: thread_rng ( ) . gen_range ( 5 , 11 ) , 0x0 ) ; generate_key ( & mut ps ) ; let mut plaintext = ps . clone ( ) ; plaintext . extend_from_slice ( b ) ; plaintext . extend_from_slice ( & ps ) ; if r % 2 == 1 { return crate :: aes_ecb :: encrypt_aes_128_ecb ( & plaintext , & key ) ; } let mut iv = [ 0 as u8 ; 16 ] ; generate_key ( & mut iv ) ; return crate :: aes_cbc :: encrypt_aes_128_cbc ( & plaintext , & key , & iv ) ; }
encryption_oracle
Solution for problem 3 from set 2: <https://cryptopals.com/sets/2/challenges/11>
encryption_oracle Solution for problem 3 from set 2 : <https : // cryptopals . com / sets / 2 / challenges / 11 >
b
&[u8]
r
u8