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 /src/crack.rs | |
parent | f955edd17464fb35df86e07bb2c3076b7e1274d8 (diff) | |
download | matasano-d895cc4c9687cd88b10d34b418eac990091fc8bd.tar.gz matasano-d895cc4c9687cd88b10d34b418eac990091fc8bd.zip |
problem 24, part 1
Diffstat (limited to 'src/crack.rs')
-rw-r--r-- | src/crack.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/crack.rs b/src/crack.rs index 92950c4..b351249 100644 --- a/src/crack.rs +++ b/src/crack.rs @@ -386,6 +386,21 @@ pub fn clone_mersenne_twister_from_output (outputs: &[u32]) -> MersenneTwister { return MersenneTwister::from_seed((state, 0)); } +pub fn recover_16_bit_mt19937_key (ciphertext: &[u8], suffix: &[u8]) -> Option<u16> { + for _key in 0..65536u32 { + let key = _key as u16; + let plaintext = ::random::mt19937_stream_cipher( + ciphertext, + key as u32 + ); + if &plaintext[(ciphertext.len() - suffix.len())..] == suffix { + return Some(key); + } + } + + return None; +} + fn crack_single_byte_xor_with_confidence (input: &[u8]) -> (u8, f64) { let mut min_diff = 100.0; let mut best_key = 0; |