stage
This commit is contained in:
29
problems/p8/src/main.rs
Normal file
29
problems/p8/src/main.rs
Normal 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.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user