summaryrefslogtreecommitdiffstats
path: root/src/crack.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2015-04-04 02:10:29 -0400
committerJesse Luehrs <doy@tozt.net>2015-04-04 02:10:29 -0400
commit72e8d6fdd8644381ee82dbcbaab208a2547c52ce (patch)
tree4b000b18207da8db71d089c4a026919e1ad029fe /src/crack.rs
parent7bcccede3eaa3d2ef01aa274e46f27e1673a1f21 (diff)
downloadmatasano-72e8d6fdd8644381ee82dbcbaab208a2547c52ce.tar.gz
matasano-72e8d6fdd8644381ee82dbcbaab208a2547c52ce.zip
problem 20
i think this is as far as possible, anyway
Diffstat (limited to 'src/crack.rs')
-rw-r--r--src/crack.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/crack.rs b/src/crack.rs
index 344488b..5bd476d 100644
--- a/src/crack.rs
+++ b/src/crack.rs
@@ -308,6 +308,55 @@ pub fn crack_cbc_padding_oracle<F> (iv: &[u8], ciphertext: &[u8], f: &F) -> Vec<
return unpad_pkcs7(&plaintext[..]).unwrap().to_vec();
}
+pub fn crack_fixed_nonce_ctr_statistically (input: Vec<Vec<u8>>) -> Vec<Vec<u8>> {
+ let min_len = input.iter().map(|line| line.len()).min().unwrap();
+ let max_len = input.iter().map(|line| line.len()).max().unwrap();
+
+ let mut plaintext_lines = vec![];
+ for _ in input.iter() {
+ plaintext_lines.push(vec![]);
+ }
+
+ let mut full_key = vec![];
+ for len in min_len..(max_len + 1) {
+ let mut idxs = vec![];
+ let ciphertext: Vec<u8> = input
+ .iter()
+ .enumerate()
+ .filter(|&(idx, line)| {
+ if line.len() >= len {
+ idxs.push(idx);
+ true
+ }
+ else {
+ false
+ }
+ })
+ .flat_map(|(_, line)| line.iter().take(len))
+ .map(|x| *x)
+ .collect();
+
+ let (key, _) = crack_repeating_key_xor_with_keysize(
+ &ciphertext[..],
+ len
+ );
+ for i in full_key.len()..key.len() {
+ full_key.push(key[i])
+ }
+
+ for idx in idxs {
+ let line = repeating_key_xor(&input[idx][..], &full_key[..])
+ .iter()
+ .take(full_key.len())
+ .map(|x| *x)
+ .collect();
+ plaintext_lines[idx] = line;
+ }
+ }
+
+ return plaintext_lines;
+}
+
fn crack_single_byte_xor_with_confidence (input: &[u8]) -> (u8, f64) {
let mut min_diff = 100.0;
let mut best_key = 0;