Skip to content

Instantly share code, notes, and snippets.

@dlwhitehurst
Created July 13, 2016 18:02
Show Gist options
  • Save dlwhitehurst/be84533f619d11c3969207b2865929f0 to your computer and use it in GitHub Desktop.
Save dlwhitehurst/be84533f619d11c3969207b2865929f0 to your computer and use it in GitHub Desktop.
Look at line 16
extern crate rustc_serialize;
use rustc_serialize::hex::{FromHex,ToHex};
/*
This is the application main
*/
fn main() {
let a = "1c0111001f010100061a024b53535009181c";
let b = "686974207468652062756c6c277320657965";
let control = "746865206b696420646f6e277420706c6179";
println!("a: {}\nb: {}\ncontrol: {}\nperformed: {}", a,b,control, xor(a,b).to_hex());
println!("What about?");
println!("b: {}\ncontrol: {}\na: {}\nperformed: {}", b,control,a, xor(b,control).to_hex());
}
/*
This function does an exclusive or operation on two hexadecimal strings
*/
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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment