Skip to content

Commit

Permalink
Benchmark math needs refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpclark committed Jan 9, 2018
1 parent a08955f commit 1f0b479
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "abrute"
version = "0.1.7"
version = "0.1.8"
authors = ["Daniel P. Clark <[email protected]>"]
description = "AESCrypt Brute force attempter."
documentation = "http:https://danielpclark.github.io/abrute/index.html"
Expand All @@ -21,3 +21,4 @@ num_cpus = "~1.7"
serde = "1.0.24"
serde_json = "1.0.8"
tiny_http = "~0.5"
lazy_static = "1.0.0"
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ use std::time::SystemTime;
use std::sync::{Arc, Mutex};
extern crate num_cpus;
extern crate tiny_http;
#[macro_use]
extern crate lazy_static;

use std::thread;
extern crate libc;
Expand Down Expand Up @@ -123,7 +125,8 @@ fn run_app() -> Result<(), Error> {
--cluster Takes an offset and cluster size such as 1:4 for the
first system in a cluster of 4. Helps different systems
split the workload without trying the same passwords.
-r, --reporter Use `spinner` for different command line reporter.
-r, --reporter Use `spinner`, or `benchmark` for different command line
reporter.
<TARGET> Target file to decrypt. The target must be preceeded
by a double dash: -- target.aes
-h, --help Prints help information.
Expand Down
2 changes: 2 additions & 0 deletions src/model/cli_reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use ::Digits;
pub enum CliReporter {
TickerTape,
Spinner,
Benchmark,
}

impl CliReporter {
Expand All @@ -11,6 +12,7 @@ impl CliReporter {
match *self {
ref _thingy @ CliReporter::TickerTape => ::reporter::ticker_tape::report(data),
ref _thingy @ CliReporter::Spinner => ::reporter::spinner::report(data),
ref _thingy @ CliReporter::Benchmark => ::reporter::benchmark::report(data),
}
}
}
5 changes: 3 additions & 2 deletions src/process_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ use ::model::cli_reporter::CliReporter;

pub fn verify_reporter_name(rn: String) -> CliReporter {
match &rn[..] {
"spinner" => CliReporter::Spinner,
_ => CliReporter::TickerTape,
"spinner" => CliReporter::Spinner,
"benchmark" => CliReporter::Benchmark,
_ => CliReporter::TickerTape,
}
}

Expand Down
62 changes: 62 additions & 0 deletions src/reporter/benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use ::{Digits,ITERATIONS};
use std::collections::HashMap;
use std::sync::Mutex;
use std::sync::atomic::Ordering;
use std::time::Instant;
use std::io;
use std::io::Write;

lazy_static! {
// len => Iterations, Iteration Start, Start Instant (for Duration)
static ref HASHMAP: Mutex<HashMap<u8, (u64, u64, Instant)>> = {
let m = HashMap::new();
Mutex::new(m)
};
}

pub fn report(data: &Digits) {
let len = data.length() as i32;
let mut hm = HASHMAP.lock().unwrap();
if hm.is_empty() {
println!("Benchmark Results\nAttempt :: Category of Range:Iterations, Rating in IPS");
hm.insert(len as u8, (0, 0, Instant::now()));
}

let reader = hm.clone();

if hm.contains_key(&(len as u8)) {
let entry = hm.get_mut(&(len as u8)).unwrap();
let &mut (_, start, duration) = entry;

let iterated = ITERATIONS.load(Ordering::SeqCst) - start.clone() as usize;

let min = reader.keys().min().unwrap();
let max = reader.keys().max().unwrap();
let start_instant = reader.get(min).unwrap().2;
let seconds = Instant::now().duration_since(start_instant).as_secs();
let ips = if seconds == 0 { 0 } else { iterated/seconds as usize };
print!("\x1b[1000D{} :: Category: {}->{}:{}, Rating: {} IPS", data.to_s(), min, max, iterated, ips);

*entry = (iterated as u64, start.clone(), duration.clone());
} else {
// New Entry
let previous = len - 1;
let has_previous = hm.contains_key(&(previous as u8));
let start_iteration = if has_previous { hm.get(&(previous as u8)).unwrap().0 } else { 0 };

let iters = ITERATIONS.load(Ordering::SeqCst);
let instant = Instant::now();

hm.insert(len as u8, (start_iteration, iters as u64, instant));

if has_previous {
let start_iters = if hm.contains_key(&((previous - 1) as u8)) { hm.get(&((previous - 1) as u8)).unwrap().0 } else { 0 };
let iterations = iters - (start_iters as usize);
let start = hm.get(&(previous as u8)).unwrap().2;
let seconds = Instant::now().duration_since(start).as_secs();
let ips = if seconds == 0 { 0 } else { iterations/(seconds as usize) };
println!("\nRange: {}, Iterations: {}, Rating: {} IPS", previous, iterations, ips);
}
}
io::stdout().flush().unwrap();
}
1 change: 1 addition & 0 deletions src/reporter/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod ticker_tape;
pub mod spinner;
pub mod benchmark;

0 comments on commit 1f0b479

Please sign in to comment.