Detect ECB via duplicated chunks instead of Hemming distance as I should have done in the first place.

This commit is contained in:
2022-04-27 10:34:40 -04:00
parent 06af500a52
commit 994da471c4
3 changed files with 35 additions and 23 deletions

View File

@@ -95,6 +95,20 @@ impl Bytes {
)
}
pub fn has_duplicated_cycle(&self, block_size: usize) -> bool {
let Bytes(v) = self;
let chunks: Vec<&[u8]> = v.chunks(block_size).collect();
// we could use a hashmap to get O(n) instead of O(n^2)
for i in 0..chunks.len() {
for j in (i + 1)..chunks.len() {
if chunks[i] == chunks[j] {
return true;
}
}
}
false
}
#[allow(dead_code)]
pub fn hemming(Bytes(a): &Bytes, Bytes(b): &Bytes) -> u32 {
let v: Vec<u32> = Iterator::zip(a.iter(), b.iter())