Skip to content

Instantly share code, notes, and snippets.

@patrickod
Created October 23, 2015 04:45
Show Gist options
  • Select an option

  • Save patrickod/c59b4f0ade85f95b6444 to your computer and use it in GitHub Desktop.

Select an option

Save patrickod/c59b4f0ade85f95b6444 to your computer and use it in GitHub Desktop.
pub fn repeating_character_xor(a: &[u8], b: u8) -> Vec<u8> {
return a.iter().map(|x| *x ^ b).collect();
}
pub fn repeating_xor(a: &[u8], b: &[u8]) -> Vec<u8> {
let cycle = b.iter();
return cycle.zip(a.iter()).map ( |(a, b)| *a ^ *b ).collect();
}
#[test]
fn test_repeating_xor() {
let a = vec![0u8, 0u8];
let b = vec![1u8];
let r = repeating_xor(&a, &b);
assert_eq!(r, &[1u8, 1u8]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment