summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2015-03-15 06:41:22 -0400
committerJesse Luehrs <doy@tozt.net>2015-03-15 06:41:22 -0400
commitd80ba0567c3a0ed16d01fd3a0b72d9c4b54db38e (patch)
tree688ca9c953e4c19cb04b806ed0d40db1e04bff6b /src
parente297730510998b5c355e52ea3c4f14e4727d7d86 (diff)
downloadmatasano-d80ba0567c3a0ed16d01fd3a0b72d9c4b54db38e.tar.gz
matasano-d80ba0567c3a0ed16d01fd3a0b72d9c4b54db38e.zip
problem 5
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index cd5fda7..0371b54 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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;