diff options
author | Jesse Luehrs <doy@tozt.net> | 2015-03-15 06:06:13 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2015-03-15 06:06:13 -0400 |
commit | d9e8984818f1fdf121b6304dd07d474ffa66dd5e (patch) | |
tree | 52bfafb5739daead2285d883e050c41eff90b0e7 | |
parent | cd5b863416a523ec2e638e3b7e112c3c1cbe5db1 (diff) | |
download | matasano-d9e8984818f1fdf121b6304dd07d474ffa66dd5e.tar.gz matasano-d9e8984818f1fdf121b6304dd07d474ffa66dd5e.zip |
factor this out
-rw-r--r-- | src/lib.rs | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -46,6 +46,11 @@ pub fn fixed_xor (bytes1: &[u8], bytes2: &[u8]) -> Vec<u8> { } pub fn crack_single_byte_xor (input: &[u8]) -> Vec<u8> { + let (decrypted, _) = crack_single_byte_xor_with_confidence(input); + return decrypted; +} + +fn crack_single_byte_xor_with_confidence (input: &[u8]) -> (Vec<u8>, f64) { let mut min_diff = 100.0; let mut best_decrypted = vec![]; for a in 0..256 { @@ -83,6 +88,5 @@ pub fn crack_single_byte_xor (input: &[u8]) -> Vec<u8> { } } - println!("{}", std::str::from_utf8(&best_decrypted[..]).unwrap()); - return best_decrypted; + return (best_decrypted, min_diff); } |