1
0
This commit is contained in:
2025-06-20 11:23:21 +08:00
commit b5601aef8c
47 changed files with 1829 additions and 0 deletions

29
problems/p8/src/main.rs Normal file
View File

@@ -0,0 +1,29 @@
use std::collections::HashSet;
use std::fs::File;
use std::io::{self, BufRead};
fn is_ecb(cipher: &[u8]) -> bool {
// Check if the input is a valid ECB encrypted data
let mut seen_blocks = HashSet::new();
for chunk in cipher.chunks(16) {
if seen_blocks.contains(chunk) {
return true; // Duplicate block found, indicating ECB mode
}
seen_blocks.insert(chunk);
}
false
}
fn main() {
let file_name = "problems/p8/8.txt".to_string();
for line in io::BufReader::new(File::open(file_name).expect("Unable to open file")).lines() {
let line = line.expect("Unable to read line");
let cipher = hex::decode(&line).expect("Invalid hex string");
if is_ecb(&cipher) {
println!("ECB detected: {}", line);
}
}
println!("Finished checking for ECB mode.");
}