diff options
author | Jesse Luehrs <doy@tozt.net> | 2015-04-05 23:49:25 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2015-04-05 23:49:33 -0400 |
commit | d895cc4c9687cd88b10d34b418eac990091fc8bd (patch) | |
tree | cf6118955ca65d6937e09f761474bc048240425e /tests | |
parent | f955edd17464fb35df86e07bb2c3076b7e1274d8 (diff) | |
download | matasano-d895cc4c9687cd88b10d34b418eac990091fc8bd.tar.gz matasano-d895cc4c9687cd88b10d34b418eac990091fc8bd.zip |
problem 24, part 1
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/lib.rs b/tests/lib.rs index 71c5e32..f498e1f 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -483,3 +483,20 @@ fn problem_22 () { assert_eq!(mt.gen::<u32>(), mt2.gen::<u32>()); } } + +#[test] +fn problem_23 () { + let key: u16 = rand::thread_rng().gen(); + let fixed_suffix = b"AAAAAAAAAAAAAA"; + let plaintext: Vec<u8> = rand::thread_rng() + .gen_iter() + .take(rand::thread_rng().gen_range(0, 32)) + .chain(fixed_suffix.iter().map(|x| *x)) + .collect(); + let ciphertext = matasano::mt19937_stream_cipher(&plaintext[..], key as u32); + let got = matasano::recover_16_bit_mt19937_key( + &ciphertext[..], + &fixed_suffix[..], + ).unwrap(); + assert_eq!(got, key); +} |