Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Estimated percentage following statistic logaritmic curve #46

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions src/pubkey_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::cmp;

use blake2::VarBlake2b;
use digest::{Update, VariableOutput};
use num_bigint::BigInt;

#[derive(Clone)]
pub struct PubkeyMatcher {
Expand Down Expand Up @@ -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)
}
}