diff --git a/src/main.rs b/src/main.rs index b9e8250..963bded 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,7 @@ extern crate num_bigint; use num_bigint::BigInt; extern crate num_traits; -use num_traits::{ToPrimitive, Zero}; +use num_traits::{Zero}; #[cfg(feature = "gpu")] extern crate ocl; @@ -115,6 +115,7 @@ fn check_solution(params: &ThreadParams, key_material: [u8; 32]) -> bool { public_key, params.simple_output, ); + params.attempts.store(0, atomic::Ordering::Relaxed); if params.limit != 0 && params.found_n.fetch_add(1, atomic::Ordering::Relaxed) + 1 >= params.limit { @@ -292,7 +293,7 @@ fn main() { .collect(); } let matcher_base = PubkeyMatcher::new(ext_pubkey_req, ext_pubkey_mask); - let estimated_attempts = matcher_base.estimated_attempts(); + let finding_chance = matcher_base.finding_chance(); let matcher_base = Arc::new(matcher_base); let limit = args .value_of("limit") @@ -333,7 +334,7 @@ fn main() { .map(|s| s.parse().expect("Failed to parse thread count option")) .unwrap_or_else(|| num_cpus::get() - 1); let mut thread_handles = Vec::with_capacity(threads); - eprintln!("Estimated attempts needed: {}", estimated_attempts); + eprintln!("Estimated attempts for 90% chance to find a match: {:.0}", -1.0_f64 / (1.0_f64 - finding_chance).log10()); for _ in 0..threads { let mut key_or_seed = [0u8; 32]; OsRng.fill_bytes(&mut key_or_seed); @@ -435,7 +436,7 @@ fn main() { thread::spawn(move || loop { let attempts = attempts.load(atomic::Ordering::Relaxed); let estimated_percent = - 100. * (attempts as f64) / estimated_attempts.to_f64().unwrap_or(f64::INFINITY); + 100. * (1.0 - (1.0 - finding_chance).powf(attempts as f64)); let runtime = start_time.elapsed(); let keys_per_second = (attempts as f64) // simplify to .as_millis() when available diff --git a/src/pubkey_matcher.rs b/src/pubkey_matcher.rs index 4e66033..c4b35c4 100644 --- a/src/pubkey_matcher.rs +++ b/src/pubkey_matcher.rs @@ -2,7 +2,6 @@ use std::cmp; use blake2::VarBlake2b; use digest::{Update, VariableOutput}; -use num_bigint::BigInt; #[derive(Clone)] pub struct PubkeyMatcher { @@ -68,11 +67,11 @@ impl PubkeyMatcher { true } - pub fn estimated_attempts(&self) -> BigInt { + pub fn finding_chance(&self) -> f64 { let mut bits_in_mask = 0; for byte in &self.mask { - bits_in_mask += byte.count_ones() as usize; + bits_in_mask += byte.count_ones() as i32; } - BigInt::from(1) << bits_in_mask + 2.0_f64.powi(-bits_in_mask) } }