cryptopals/examples/set1_4/main.rs

20 lines
583 B
Rust
Raw Normal View History

2023-04-27 04:58:19 +00:00
use cryptopals::{prelude::*, bvecs};
fn main() {
let inputs = bvecs!("inputs.txt");
let best = (u8::MIN..=u8::MAX).flat_map(
|possibility| {
inputs.iter().map(move |input| {
let result = input.xor_repeating(&vec![possibility]).unwrap();
let score = cryptopals::english::score(&result);
(possibility, result, score, input)
})
}
).max_by_key(|(_,_,score, _)| *score).unwrap();
dbg!(best.0);
dbg!(best.1.to_text().unwrap());
dbg!(best.3.to_hex());
println!("pass!")
}