remove threading logic, just stop it manually when it finds it for now
This commit is contained in:
parent
89a4d7570e
commit
9365392c2f
1 changed files with 23 additions and 45 deletions
68
src/main.rs
68
src/main.rs
|
@ -3,7 +3,6 @@ extern crate hex;
|
||||||
extern crate num_cpus;
|
extern crate num_cpus;
|
||||||
|
|
||||||
use crypto_hash::{hex_digest, Algorithm};
|
use crypto_hash::{hex_digest, Algorithm};
|
||||||
use std::sync::mpsc::{self, TryRecvError};
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -12,52 +11,31 @@ fn main() {
|
||||||
let increment: u32 = 0xffffffff / core_count;
|
let increment: u32 = 0xffffffff / core_count;
|
||||||
let mut threads = Vec::new();
|
let mut threads = Vec::new();
|
||||||
for thread_index in 0..core_count {
|
for thread_index in 0..core_count {
|
||||||
let (tx, rx) = mpsc::channel();
|
threads.push(thread::spawn(move || {
|
||||||
threads.push((
|
println!(
|
||||||
thread::spawn(move || {
|
"Spawned thread #{:?} with characters {:?} through {:?}\ntarget is {:?}",
|
||||||
println!(
|
thread_index,
|
||||||
"Spawned thread #{:?} with characters {:?} through {:?}\ntarget is {:?}",
|
increment * thread_index,
|
||||||
thread_index,
|
increment * (thread_index + 1),
|
||||||
increment * thread_index,
|
target
|
||||||
increment * (thread_index + 1),
|
);
|
||||||
target
|
for x in increment * thread_index..increment * (thread_index + 1) {
|
||||||
);
|
let byte_vec = trim_bytes(x);
|
||||||
for x in increment * thread_index..increment * (thread_index + 1) {
|
let hash = hex_digest(Algorithm::SHA256, byte_vec.as_slice());
|
||||||
match rx.try_recv() {
|
if hash == target {
|
||||||
Ok(_) | Err(TryRecvError::Disconnected) => {
|
println!(
|
||||||
println!("Terminating.");
|
"\n########\n# FOUND - {:?} - {:?}\n########\n",
|
||||||
break;
|
hex::encode(x.to_be_bytes()),
|
||||||
}
|
hex_digest(Algorithm::SHA256, trim_bytes(x).as_slice())
|
||||||
Err(TryRecvError::Empty) => {}
|
);
|
||||||
}
|
break;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}),
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue