pub fn break_fixed_nonce_ctr(
    input: &Vec<Vec<u8>>,
    k: &[u8],
) -> Result<Vec<Vec<u8>>, symmetriccipher::SymmetricCipherError> {
    let mut ciphertexts: Vec<Vec<u8>> = Vec::new();
    let mut longest = 0;
    for line in input {
        if line.len() > longest {
            longest = line.len();
        }

        ciphertexts.push(crate::aes_ctr::aes_128_ctr(&line, k, &[0 as u8; 8])?);
    }

    let to_break: Vec<_> = ciphertexts.iter().cloned().map(|x| x).collect();
    let mut key = Vec::new();

    for column in 0..longest {
        let column_vec: Vec<_> = to_break
            .iter()
            .map(|x| match x.get(column) {
                Some(v) => *v,
                None => to_break[0][0],
            })
            .collect();
        let (_, k, _) = crate::set1::single_byte_xor(hex::encode(&column_vec).as_bytes()).unwrap();
        key.push(k);
    }

    let mut plaintexts = Vec::new();

    for v in to_break {
        let plaintext = crate::set1::xor_buffers(
            hex::encode(&v).as_bytes(),
            hex::encode(&key[..v.len()]).as_bytes(),
        )
        .unwrap();

        plaintexts.push(plaintext);
    }

    Ok(plaintexts)
}
/// break_fixed_nonce_ctr breaks aes_ctr with fixed nonce
///
/// Solution for problem 3 from set 3: <https://cryptopals.com/sets/3/challenges/19>
break_fixed_nonce_ctr breaks aes_ctr with fixed nonce
Solution for problem 3 from set 3.
break_fixed_nonce_ctr breaks aes_ctr with fixed nonce Solution for problem 3 from set 3 .
pub fn break_fixed_nonce_ctr(
    input: &Vec<Vec<u8>>,
    k: &[u8],
) -> Result<Vec<Vec<u8>>, symmetriccipher::SymmetricCipherError> {
    let mut ciphertexts: Vec<Vec<u8>> = Vec::new();
    let mut longest = 0;
    for line in input {
        if line.len() > longest {
            longest = line.len();
        }
        ciphertexts.push(crate::aes_ctr::aes_128_ctr(&line, k, &[0 as u8; 8])?);
    }
    let to_break: Vec<_> = ciphertexts.iter().cloned().map(|x| x).collect();
    let mut key = Vec::new();
    for column in 0..longest {
        let column_vec: Vec<_> = to_break
            .iter()
            .map(|x| match x.get(column) {
                Some(v) => *v,
                None => to_break[0][0],
            })
            .collect();
        let (_, k, _) = crate::set1::single_byte_xor(hex::encode(&column_vec).as_bytes()).unwrap();
        key.push(k);
    }
    let mut plaintexts = Vec::new();
    for v in to_break {
        let plaintext = crate::set1::xor_buffers(
            hex::encode(&v).as_bytes(),
            hex::encode(&key[..v.len()]).as_bytes(),
        )
        .unwrap();
        plaintexts.push(plaintext);
    }
    Ok(plaintexts)
}
pub fn break_fixed_nonce_ctr ( input : & Vec < Vec < u8 > > , k : & [ u8 ] , ) -> Result < Vec < Vec < u8 > > , symmetriccipher :: SymmetricCipherError > { let mut ciphertexts : Vec < Vec < u8 > > = Vec :: new ( ) ; let mut longest = 0 ; for line in input { if line . len ( ) > longest { longest = line . len ( ) ; } ciphertexts . push ( crate :: aes_ctr :: aes_128_ctr ( & line , k , & [ 0 as u8 ; 8 ] ) ? ) ; } let to_break : Vec < _ > = ciphertexts . iter ( ) . cloned ( ) . map ( | x | x ) . collect ( ) ; let mut key = Vec :: new ( ) ; for column in 0 .. longest { let column_vec : Vec < _ > = to_break . iter ( ) . map ( | x | match x . get ( column ) { Some ( v ) => * v , None => to_break [ 0 ] [ 0 ] , } ) . collect ( ) ; let ( _ , k , _ ) = crate :: set1 :: single_byte_xor ( hex :: encode ( & column_vec ) . as_bytes ( ) ) . unwrap ( ) ; key . push ( k ) ; } let mut plaintexts = Vec :: new ( ) ; for v in to_break { let plaintext = crate :: set1 :: xor_buffers ( hex :: encode ( & v ) . as_bytes ( ) , hex :: encode ( & key [ .. v . len ( ) ] ) . as_bytes ( ) , ) . unwrap ( ) ; plaintexts . push ( plaintext ) ; } Ok ( plaintexts ) }
break_fixed_nonce_ctr breaks aes_ctr with fixed nonce
Solution for problem 3 from set 3: <https://cryptopals.com/sets/3/challenges/19>
break_fixed_nonce_ctr breaks aes_ctr with fixed nonce Solution for problem 3 from set 3 : <https : // cryptopals . com / sets / 3 / challenges / 19 >
input
&Vec<Vec<u8>>
k
&[u8]