Detect ECB via duplicated chunks instead of Hemming distance as I should have done in the first place.
This commit is contained in:
14
src/bytes.rs
14
src/bytes.rs
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user