Created
April 9, 2015 17:26
-
-
Save swizard0/6f4df8bdea0db32833fd to your computer and use it in GitHub Desktop.
This file contains 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
extern crate crypto; | |
extern crate sys_info; | |
extern crate rustc_serialize; | |
use std::sync::{Arc, mpsc}; | |
use crypto::md5::Md5; | |
use crypto::digest::Digest; | |
use rustc_serialize::hex::FromHex; | |
fn next_byte(x: u8) -> u8 { | |
match x { | |
0x39 => 0x61, // '9' => 'a' | |
0x7a => 0x30, // 'z' => '0' | |
_ => x + 1, | |
} | |
} | |
fn next_pass(buf: &mut [u8]) { | |
for b in buf.iter_mut().rev() { | |
*b = next_byte(*b); | |
if *b != 0x30 { | |
break | |
} | |
} | |
} | |
fn worker(sample: Arc<Vec<u8>>, rx: mpsc::Receiver<(Vec<u8>, u8)>, tx: mpsc::Sender<Vec<u8>>) { | |
let mut md5 = Md5::new(); | |
let result: &mut [u8] = &mut [0; 16]; | |
loop { | |
match rx.recv() { | |
Ok((mut pass, end)) => { | |
while pass[0] != end { | |
md5.reset(); | |
md5.input(&pass); | |
md5.result(result); | |
if result == &**sample { | |
tx.send(pass).unwrap(); | |
return; | |
} | |
next_pass(&mut pass); | |
} | |
}, | |
Err(mpsc::RecvError) => | |
break, | |
} | |
} | |
} | |
fn main() { | |
let sample = Arc::new("95ebc3c7b3b9f1d2c40fec14415d3cb8".from_hex().unwrap()); | |
let (rep_tx, rep_rx) = mpsc::channel(); | |
let workers: Vec<_> = (0 .. sys_info::cpu_num().unwrap()) | |
.map(|_| { | |
let (req_tx, req_rx) = mpsc::channel(); | |
let sample = sample.clone(); | |
let rep_tx = rep_tx.clone(); | |
std::thread::spawn(move || { worker(sample, req_rx, rep_tx); }); | |
req_tx | |
}).collect(); | |
let mut pass = vec![0x30, 0x30, 0x30, 0x30, 0x30]; | |
for i in 0 .. { | |
let end = next_byte(pass[0]); | |
workers[i % workers.len()].send((pass.clone(), end)).unwrap(); | |
pass[0] = end; | |
if end == 0x30 { break } | |
} | |
println!("found password: {}", String::from_utf8(rep_rx.recv().unwrap()).unwrap()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment