Created
October 23, 2015 04:45
-
-
Save patrickod/c59b4f0ade85f95b6444 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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