Skip to content

Instantly share code, notes, and snippets.

@dlwhitehurst
Created July 13, 2016 17:48
Show Gist options
  • Save dlwhitehurst/bd4b6acee4fb861b5319dffc92798ac9 to your computer and use it in GitHub Desktop.
Save dlwhitehurst/bd4b6acee4fb861b5319dffc92798ac9 to your computer and use it in GitHub Desktop.
Scoping Issue in Assert? Doesn't compile. Says to_hex() not available.
use rustc_serialize::hex::ToHex;
use rustc_serialize::hex::FromHex;
pub fn xor(a: &str, b: &str) -> Vec<u8> {
return a.from_hex().unwrap().iter().zip(b.from_hex().unwrap().iter()).map(|(&x,&y)|x^y).collect();
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works2() {
let a = "1c0111001f010100061a024b53535009181c";
let b = "686974207468652062756c6c277320657965";
let control = "746865206b696420646f6e277420706c6179";
let result = xor(a,b);
assert_eq!("746865206b696420646f6e277420706c6179",result.to_hex());
}
} // end mod tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment