pub fn break_mt19937_stream_cipher(seed: i16, b: &[u8]) -> Option<i16> {
    let msg_string = String::from_utf8(Vec::from(b)).unwrap();

    let encrypt = |b: &[u8]| -> Vec<u8> {
        let mut prefix: Vec<u8> = vec![b'B', (seed % 16) as u8];
        prefix.extend_from_slice(b);
        prefix.extend_from_slice(";password_reset=true".as_bytes());

        return crate::mt_19937_cipher::mt19937_stream_cipher(seed, &prefix);
    };

    let ciphertext = encrypt(b);
    for i in std::i16::MIN..std::i16::MAX {
        let plaintext_bytes = crate::mt_19937_cipher::mt19937_stream_cipher(i, &ciphertext);
        let plaintext_string = String::from_utf8_lossy(&plaintext_bytes);

        if plaintext_string.contains(&msg_string) {
            return Some(i);
        }
    }

    None
}
/// break_mt19937_stream_cipher breaks the mt19937 stream cipher
///
/// Solution for problem 8 from set 3: <https://cryptopals.com/sets/3/challenges/24>
break_mt19937_stream_cipher breaks the mt19937 stream cipher
Solution for problem 8 from set 3.
break_mt19937_stream_cipher breaks the mt19937 stream cipher Solution for problem 8 from set 3 .
pub fn break_mt19937_stream_cipher(seed: i16, b: &[u8]) -> Option<i16> {
    let msg_string = String::from_utf8(Vec::from(b)).unwrap();
    let encrypt = |b: &[u8]| -> Vec<u8> {
        let mut prefix: Vec<u8> = vec![b'B', (seed % 16) as u8];
        prefix.extend_from_slice(b);
        prefix.extend_from_slice(";password_reset=true".as_bytes());
        return crate::mt_19937_cipher::mt19937_stream_cipher(seed, &prefix);
    };
    let ciphertext = encrypt(b);
    for i in std::i16::MIN..std::i16::MAX {
        let plaintext_bytes = crate::mt_19937_cipher::mt19937_stream_cipher(i, &ciphertext);
        let plaintext_string = String::from_utf8_lossy(&plaintext_bytes);
        if plaintext_string.contains(&msg_string) {
            return Some(i);
        }
    }
    None
}
pub fn break_mt19937_stream_cipher ( seed : i16 , b : & [ u8 ] ) -> Option < i16 > { let msg_string = String :: from_utf8 ( Vec :: from ( b ) ) . unwrap ( ) ; let encrypt = | b : & [ u8 ] | -> Vec < u8 > { let mut prefix : Vec < u8 > = vec ! [ b'B' ( seed 16 ) as u8 ] ; prefix . extend_from_slice ( b ) ; prefix . extend_from_slice ( " " . as_bytes ( ) ) ; return crate :: mt_19937_cipher :: mt19937_stream_cipher ( seed , & prefix ) ; } ; let ciphertext = encrypt ( b ) ; for i in std :: i16 :: MIN .. std :: i16 :: MAX { let plaintext_bytes = crate :: mt_19937_cipher :: mt19937_stream_cipher ( i , & ciphertext ) ; let plaintext_string = String :: from_utf8_lossy ( & plaintext_bytes ) ; if plaintext_string . contains ( & msg_string ) { return Some ( i ) ; } } None }
break_mt19937_stream_cipher breaks the mt19937 stream cipher
Solution for problem 8 from set 3: <https://cryptopals.com/sets/3/challenges/24>
break_mt19937_stream_cipher breaks the mt19937 stream cipher Solution for problem 8 from set 3 : <https : // cryptopals . com / sets / 3 / challenges / 24 >
seed
i16
b
&[u8]