use into_iter to iterate key bytes by value
This commit is contained in:
parent
41581053dd
commit
25b1621892
|
@ -13,12 +13,12 @@ pub fn score(plaintext: &Vec<u8>) -> u32 {
|
|||
score
|
||||
}
|
||||
|
||||
pub fn fixed_xor_cipher(ciphertext: &Vec<u8>, keyiter: &mut dyn Iterator<Item = &u8>) -> Vec<u8> {
|
||||
pub fn fixed_xor_cipher(ciphertext: &Vec<u8>, keyiter: &mut dyn Iterator<Item = u8>) -> Vec<u8> {
|
||||
ciphertext.iter().zip(keyiter).map(|(c, k)| c ^ k).collect()
|
||||
}
|
||||
|
||||
pub fn xor_cipher(ciphertext: &Vec<u8>, key: u8) -> Vec<u8> {
|
||||
fixed_xor_cipher(ciphertext, &mut repeat(&key))
|
||||
fixed_xor_cipher(ciphertext, &mut repeat(key))
|
||||
}
|
||||
|
||||
pub fn break_xor_cipher(ciphertext: &Vec<u8>) -> (Vec<u8>, u32) {
|
||||
|
|
|
@ -23,7 +23,7 @@ fn main() {
|
|||
|
||||
for (line1, line2) in Pairwise(stdin.lock().lines().filter_map(|x| x.ok())) {
|
||||
match (line1.from_hex(), line2.from_hex()) {
|
||||
(Ok(v1), Ok(v2)) => println!("{}", fixed_xor_cipher(&v1, &mut v2.iter()).to_hex()),
|
||||
(Ok(v1), Ok(v2)) => println!("{}", fixed_xor_cipher(&v1, &mut v2.into_iter()).to_hex()),
|
||||
(Err(e), _) => error!("{}", e),
|
||||
(_, Err(e)) => error!("{}", e)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue