Skip to content

Instantly share code, notes, and snippets.

@dlwhitehurst
Created July 13, 2016 17:58
Show Gist options
  • Save dlwhitehurst/524f479be0e0f1350ddc64a3c2ec13e3 to your computer and use it in GitHub Desktop.
Save dlwhitehurst/524f479be0e0f1350ddc64a3c2ec13e3 to your computer and use it in GitHub Desktop.
The to_hex() is the problem now in assert macro, not when used with println! in another module.
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 {
extern crate rustc_serialize;
use super::*;
use rustc_serialize::hex::ToHex;
use rustc_serialize::hex::FromHex;
#[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