From 96422481271c8b6cd0ec095db44ac85525edf688 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Mon, 5 Dec 2016 12:35:05 +0200 Subject: AOC5 --- aoc5/Cargo.lock | 12 ++++++++++++ aoc5/Cargo.toml | 7 +++++++ aoc5/src/main.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 aoc5/Cargo.lock create mode 100644 aoc5/Cargo.toml create mode 100644 aoc5/src/main.rs (limited to 'aoc5') diff --git a/aoc5/Cargo.lock b/aoc5/Cargo.lock new file mode 100644 index 0000000..6d0e69c --- /dev/null +++ b/aoc5/Cargo.lock @@ -0,0 +1,12 @@ +[root] +name = "aoc5" +version = "0.1.0" +dependencies = [ + "md5 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "md5" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + diff --git a/aoc5/Cargo.toml b/aoc5/Cargo.toml new file mode 100644 index 0000000..cc09c3c --- /dev/null +++ b/aoc5/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "aoc5" +version = "0.1.0" +authors = ["Justin Worthe "] + +[dependencies] +md5 = "^0.2" \ No newline at end of file diff --git a/aoc5/src/main.rs b/aoc5/src/main.rs new file mode 100644 index 0000000..31bef5e --- /dev/null +++ b/aoc5/src/main.rs @@ -0,0 +1,49 @@ +extern crate md5; + +fn main() { + let room = "reyedfim"; + + let mut i = 0; + let mut found_bytes = 0; + + let mut code: [Option; 8] = [None;8]; + + println!("Cracking the passwordz"); + print_code(&code); + + while found_bytes < 8 { + let room_string = format!("{}{}", room, i); + let room_bytes = room_string.into_bytes(); + let hash = md5::compute(room_bytes.as_slice()); + if match_hash(hash) { + let position = hash[2]; + let value = hash[3] / 16; + if code[position as usize].is_none() { + code[position as usize] = Some(value); + print_code(&code); + found_bytes += 1; + } + } + + i+=1; + } + + println!("Password found!"); +} + +fn match_hash(hash: [u8; 16]) -> bool { + hash[0] == 0 && + hash[1] == 0 && + hash[2] < 8 +} + +fn print_code(code: &[Option; 8]) { + println!(""); + for &byte in code.iter() { + match byte { + None => {print!("-");}, + Some(x) => {print!("{:x}", x);} + } + } + println!(""); +} -- cgit v1.2.3