pub fn cbc_oracle(random_msgs: &[String], k: &[u8], iv: &[u8]) -> String {
    let msg =
        base64::decode(random_msgs[rand::thread_rng().gen_range(0, random_msgs.len())].as_bytes())
            .unwrap();

    let ciphertext = encrypt_random_chosen_msg(&msg, k, iv).unwrap();
    let block_size = 16; // 128 bit

    let mut plaintext = Vec::new();

    let mut iter = ciphertext.chunks(block_size);
    let mut previous_block = iv;
    loop {
        let current_block = match iter.next() {
            Some(v) => v,
            None => break,
        };

        plaintext.extend_from_slice(&attack_two_cbc_blocks(
            block_size,
            previous_block,
            current_block,
            k,
            iv,
        ));

        previous_block = current_block;
    }

    String::from_utf8_lossy(&plaintext).to_string()
}
/// cbc_oracle decrypts the ciphertext without the key.
///
/// Solution for problem 1 from set 3: <https://cryptopals.com/sets/3/challenges/17>
cbc_oracle decrypts the ciphertext without the key.
Solution for problem 1 from set 3.
cbc_oracle decrypts the ciphertext without the key . Solution for problem 1 from set 3 .
pub fn cbc_oracle(random_msgs: &[String], k: &[u8], iv: &[u8]) -> String {
    let msg =
        base64::decode(random_msgs[rand::thread_rng().gen_range(0, random_msgs.len())].as_bytes())
            .unwrap();
    let ciphertext = encrypt_random_chosen_msg(&msg, k, iv).unwrap();
    let block_size = 16; // 128 bit
    let mut plaintext = Vec::new();
    let mut iter = ciphertext.chunks(block_size);
    let mut previous_block = iv;
    loop {
        let current_block = match iter.next() {
            Some(v) => v,
            None => break,
        };
        plaintext.extend_from_slice(&attack_two_cbc_blocks(
            block_size,
            previous_block,
            current_block,
            k,
            iv,
        ));
        previous_block = current_block;
    }
    String::from_utf8_lossy(&plaintext).to_string()
}
pub fn cbc_oracle ( random_msgs : & [ String ] , k : & [ u8 ] , iv : & [ u8 ] ) -> String { let msg = base64 :: decode ( random_msgs [ rand :: thread_rng ( ) . gen_range ( 0 , random_msgs . len ( ) ) ] . as_bytes ( ) ) . unwrap ( ) ; let ciphertext = encrypt_random_chosen_msg ( & msg , k , iv ) . unwrap ( ) ; let block_size = 16 ; // 128 bit let mut plaintext = Vec :: new ( ) ; let mut iter = ciphertext . chunks ( block_size ) ; let mut previous_block = iv ; loop { let current_block = match iter . next ( ) { Some ( v ) => v , None => break , } ; plaintext . extend_from_slice ( & attack_two_cbc_blocks ( block_size , previous_block , current_block , k , iv , ) ) ; previous_block = current_block ; } String :: from_utf8_lossy ( & plaintext ) . to_string ( ) }
cbc_oracle decrypts the ciphertext without the key.
cbc_oracle decrypts the ciphertext without the key .
random_msgs
&[String]
k
&[u8]
iv
&[u8]