extern crate crypto_hash; extern crate hex; extern crate num_cpus; use crypto_hash::{hex_digest, Algorithm}; use std::thread; fn main() { let target = "01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b"; let core_count = num_cpus::get() as u32; let increment: u32 = 0xffffffff / core_count; let mut threads = Vec::new(); for thread_index in 0..core_count { threads.push(thread::spawn(move || { println!( "Spawned thread #{:?} with characters {:?} through {:?}\ntarget is {:?}", thread_index, increment * thread_index, increment * (thread_index + 1), target ); for x in increment * thread_index..increment * (thread_index + 1) { let byte_vec = trim_bytes(x); let hash = hex_digest(Algorithm::SHA256, byte_vec.as_slice()); if hash == target { println!( "\n########\n# FOUND - {:?} - {:?}\n########\n", hex::encode(x.to_be_bytes()), hex_digest(Algorithm::SHA256, trim_bytes(x).as_slice()) ); break; } } })); } for thread in threads { thread.join().unwrap(); } } fn trim_bytes<'a>(x: u32) -> Vec { let full_byte_array = x.to_be_bytes(); let mut v: Vec = Vec::new(); let mut has_encountered_value = false; for byte in &full_byte_array { if has_encountered_value { v.push(*byte); } else { if *byte != 0u8 { v.push(*byte); has_encountered_value = true; } } } v }