pub fn break_repeating_xor_cipher(b: &[u8]) -> Result<Vec<u8>, hex::FromHexError> {
    let (mut score, mut size) = (1000, 0);
    // Find the keysize.
    for key_size in 2..41 {
        let chunk1 = &b[..4 * key_size];
        let chunk2 = &b[4 * key_size..(8 * key_size % b.len())];

        let dist = hamming_distance(
            &hex::encode(&chunk1).into_bytes(),
            &hex::encode(&chunk2).into_bytes(),
        )? / key_size;

        if dist <= score {
            score = dist;
            size = key_size
        }
    }

    let mut key: Vec<u8> = Vec::with_capacity(size);
    for i in 0..size {
        let d: Vec<_> = b.chunks(size).filter_map(|x| x.get(i).cloned()).collect();
        let (_, k, _) = single_byte_xor(&hex::encode(d).into_bytes())?;
        key.push(k);
    }

    Ok(key)
}
/// Break repeating XOR-cipher
///
/// Solution for problem 6 from set1: <https://cryptopals.com/sets/1/challenges/6>
Break repeating XOR-cipher
Solution for problem 6 from set1.
Break repeating XOR - cipher Solution for problem 6 from set1 .
pub fn break_repeating_xor_cipher(b: &[u8]) -> Result<Vec<u8>, hex::FromHexError> {
    let (mut score, mut size) = (1000, 0);
    // Find the keysize.
    for key_size in 2..41 {
        let chunk1 = &b[..4 * key_size];
        let chunk2 = &b[4 * key_size..(8 * key_size % b.len())];
        let dist = hamming_distance(
            &hex::encode(&chunk1).into_bytes(),
            &hex::encode(&chunk2).into_bytes(),
        )? / key_size;
        if dist <= score {
            score = dist;
            size = key_size
        }
    }
    let mut key: Vec<u8> = Vec::with_capacity(size);
    for i in 0..size {
        let d: Vec<_> = b.chunks(size).filter_map(|x| x.get(i).cloned()).collect();
        let (_, k, _) = single_byte_xor(&hex::encode(d).into_bytes())?;
        key.push(k);
    }
    Ok(key)
}
pub fn break_repeating_xor_cipher ( b : & [ u8 ] ) -> Result < Vec < u8 > , hex :: FromHexError > { let ( mut score , mut size ) = ( 1000 , 0 ) ; // Find the keysize. for key_size in 2 .. 41 { let chunk1 = & b [ .. 4 * key_size ] ; let chunk2 = & b [ 4 * key_size .. ( 8 * key_size % b . len ( ) ) ] ; let dist = hamming_distance ( & hex :: encode ( & chunk1 ) . into_bytes ( ) , & hex :: encode ( & chunk2 ) . into_bytes ( ) , ) ? / key_size ; if dist <= score { score = dist ; size = key_size } } let mut key : Vec < u8 > = Vec :: with_capacity ( size ) ; for i in 0 .. size { let d : Vec < _ > = b . chunks ( size ) . filter_map ( | x | x . get ( i ) . cloned ( ) ) . collect ( ) ; let ( _ , k , _ ) = single_byte_xor ( & hex :: encode ( d ) . into_bytes ( ) ) ? ; key . push ( k ) ; } Ok ( key ) }
Break repeating XOR-cipher
Solution for problem 6 from set1: <https://cryptopals.com/sets/1/challenges/6>
Break repeating XOR - cipher Solution for problem 6 from set1 : <https : // cryptopals . com / sets / 1 / challenges / 6 >
b
&[u8]