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; | ||||
| 
 | ||||
| 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(); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue