From 9365392c2fa09035f4daa1928f3a8cbf955b4a62 Mon Sep 17 00:00:00 2001 From: edensg Date: Fri, 1 Nov 2019 20:40:20 -0400 Subject: [PATCH] remove threading logic, just stop it manually when it finds it for now --- src/main.rs | 68 ++++++++++++++++++----------------------------------- 1 file changed, 23 insertions(+), 45 deletions(-) diff --git a/src/main.rs b/src/main.rs index cc101da..04d5e17 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,6 @@ extern crate hex; extern crate num_cpus; use crypto_hash::{hex_digest, Algorithm}; -use std::sync::mpsc::{self, TryRecvError}; use std::thread; fn main() { @@ -12,52 +11,31 @@ fn main() { let increment: u32 = 0xffffffff / core_count; let mut threads = Vec::new(); for thread_index in 0..core_count { - let (tx, rx) = mpsc::channel(); - 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) { - match rx.try_recv() { - Ok(_) | Err(TryRecvError::Disconnected) => { - println!("Terminating."); - break; - } - Err(TryRecvError::Empty) => {} - } - let byte_vec = trim_bytes(x); - let hash = hex_digest(Algorithm::SHA256, byte_vec.as_slice()); - if hash == target { - println!( - "{:?} - {:?}", - hex::encode(x.to_be_bytes()), - hex_digest(Algorithm::SHA256, trim_bytes(x).as_slice()) - ); - break; - } + 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; } - }), - tx, - )); - } - loop { - for thread in threads { - match thread.1.try_recv() { - Ok(_) => { - for thread in threads { - - break; - } - } - Err(_) => {} } - } - is_first_loop = false; + })); + } + + for thread in threads { + thread.join().unwrap(); } }