diff options
author | Jesse Luehrs <doy@tozt.net> | 2015-03-15 06:41:22 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2015-03-15 06:41:22 -0400 |
commit | d80ba0567c3a0ed16d01fd3a0b72d9c4b54db38e (patch) | |
tree | 688ca9c953e4c19cb04b806ed0d40db1e04bff6b /src | |
parent | e297730510998b5c355e52ea3c4f14e4727d7d86 (diff) | |
download | matasano-d80ba0567c3a0ed16d01fd3a0b72d9c4b54db38e.tar.gz matasano-d80ba0567c3a0ed16d01fd3a0b72d9c4b54db38e.zip |
problem 5
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -45,6 +45,18 @@ pub fn fixed_xor (bytes1: &[u8], bytes2: &[u8]) -> Vec<u8> { .collect(); } +pub fn repeating_key_xor (plaintext: &[u8], key: &[u8]) -> Vec<u8> { + return fixed_xor( + plaintext, + &key + .iter() + .cycle() + .take(plaintext.len()) + .map(|c| *c) + .collect::<Vec<u8>>()[..] + ); +} + pub fn crack_single_byte_xor (input: &[u8]) -> Vec<u8> { let (decrypted, _) = crack_single_byte_xor_with_confidence(input); return decrypted; |