messing arround
This commit is contained in:
parent
4302adad55
commit
bbb9241869
77
src/main.rs
77
src/main.rs
@ -6,14 +6,29 @@ use std::time::{Duration, Instant};
|
|||||||
|
|
||||||
use num_format::{Locale, ToFormattedString};
|
use num_format::{Locale, ToFormattedString};
|
||||||
|
|
||||||
const ALL_CHARS_95: &'static str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.<>/?;':\"[]{}\\|-=_+`~!@#$%^&*() ";
|
/// The length of the combination
|
||||||
// const ALL_ALPHA: &'static str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
const LEN: usize = 5;
|
||||||
// const ALL_ALPHA_NUM: &'static str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
||||||
|
|
||||||
const LEN: usize = 8;
|
|
||||||
|
|
||||||
|
/// How many combinations have we create thus far
|
||||||
static mut TOTAL: usize = 0;
|
static mut TOTAL: usize = 0;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
enum Charset {
|
||||||
|
AllChars,
|
||||||
|
AllAlpha,
|
||||||
|
AllAlphaAndNum
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Charset {
|
||||||
|
fn as_str(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Charset::AllChars => "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.<>/?;':\"[]{}\\|-=_+`~!@#$%^&*() ",
|
||||||
|
Charset::AllAlpha => "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||||
|
Charset::AllAlphaAndNum => "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Pseudo main
|
/// Pseudo main
|
||||||
///
|
///
|
||||||
/// Starts the number crunching (blocking on main thread!) and the
|
/// Starts the number crunching (blocking on main thread!) and the
|
||||||
@ -24,7 +39,7 @@ fn start(char_list: &str, output_len: usize) {
|
|||||||
/// timer threads.
|
/// timer threads.
|
||||||
static mut IS_DONE: bool = false;
|
static mut IS_DONE: bool = false;
|
||||||
/// Seconds between the calculating p/s and percentage done.
|
/// Seconds between the calculating p/s and percentage done.
|
||||||
const CHECK_IN_DELAY: u64 = 1;
|
const CHECK_IN_DELAY: u64 = 2;
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
// Try multithreading...
|
// Try multithreading...
|
||||||
@ -32,7 +47,7 @@ fn start(char_list: &str, output_len: usize) {
|
|||||||
let mut counters = Vec::new();
|
let mut counters = Vec::new();
|
||||||
let mut buffers = Vec::new();
|
let mut buffers = Vec::new();
|
||||||
|
|
||||||
// Start threads
|
// Start generating threads
|
||||||
for i in char_list.chars() {
|
for i in char_list.chars() {
|
||||||
let counter = Arc::new(RwLock::new(0u128));
|
let counter = Arc::new(RwLock::new(0u128));
|
||||||
let buffer = Arc::new(RwLock::new(Vec::new()));
|
let buffer = Arc::new(RwLock::new(Vec::new()));
|
||||||
@ -47,18 +62,18 @@ fn start(char_list: &str, output_len: usize) {
|
|||||||
tasks.push(worker);
|
tasks.push(worker);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just to report stats
|
// A thread just to report stats
|
||||||
let timer = thread::spawn(move || {
|
let timer = thread::spawn(move || {
|
||||||
let mut out = stderr();
|
let mut out = stderr();
|
||||||
|
|
||||||
while unsafe { !IS_DONE } {
|
while unsafe { !IS_DONE } {
|
||||||
let mut elapsed = start.elapsed().as_secs() as u128;
|
let mut seconds_elapsed = start.elapsed().as_secs() as u128;
|
||||||
// prevent div by zero err
|
// prevent div by zero err
|
||||||
if elapsed == 0 { elapsed = 1; }
|
if seconds_elapsed == 0 { seconds_elapsed = 1; }
|
||||||
|
|
||||||
let mut sofar =0;
|
let mut combinations =0;
|
||||||
for ele in &counters {
|
for i in &counters {
|
||||||
sofar += *ele.read().unwrap();
|
combinations += *i.read().unwrap();
|
||||||
};
|
};
|
||||||
|
|
||||||
// This doesn't free the memory fast enough! // FIXME
|
// This doesn't free the memory fast enough! // FIXME
|
||||||
@ -69,15 +84,26 @@ fn start(char_list: &str, output_len: usize) {
|
|||||||
}
|
}
|
||||||
// prevent memory footprint from getting too big
|
// prevent memory footprint from getting too big
|
||||||
i.write().unwrap().clear();
|
i.write().unwrap().clear();
|
||||||
println!("clear")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// output P/s
|
let time_remaining = {
|
||||||
|
let seconds_remaining = (unsafe {TOTAL as u128} - combinations) * seconds_elapsed;
|
||||||
|
// TODO hours in inacuate?
|
||||||
|
let hours = (seconds_remaining / 60) / 60;
|
||||||
|
let minutes = (seconds_remaining / 60) % 60;
|
||||||
|
let seconds = seconds_remaining % 60;
|
||||||
|
|
||||||
|
format!("{hours}h:{minutes}m:{seconds}s")
|
||||||
|
};
|
||||||
|
|
||||||
|
// output stats
|
||||||
let _ = out.write(
|
let _ = out.write(
|
||||||
format!("\rCalculated {}, at {}p/s, {:.5}%",
|
format!("\rCalculated {}, at {}p/s, {:.5}%, elapsed: {}s {}",
|
||||||
sofar.to_formatted_string(&Locale::en_NA),
|
combinations.to_formatted_string(&Locale::en_NA),
|
||||||
(sofar / elapsed).to_formatted_string(&Locale::en_NA),
|
(combinations / seconds_elapsed).to_formatted_string(&Locale::en_NA),
|
||||||
sofar as f64 / unsafe { TOTAL as f64 } * 100f64,
|
combinations as f64 / unsafe { TOTAL as f64 } * 100f64,
|
||||||
|
seconds_elapsed,
|
||||||
|
time_remaining
|
||||||
).as_bytes());
|
).as_bytes());
|
||||||
let _ = out.flush();
|
let _ = out.flush();
|
||||||
sleep(Duration::from_secs(CHECK_IN_DELAY));
|
sleep(Duration::from_secs(CHECK_IN_DELAY));
|
||||||
@ -89,21 +115,26 @@ fn start(char_list: &str, output_len: usize) {
|
|||||||
unsafe { IS_DONE = true; }
|
unsafe { IS_DONE = true; }
|
||||||
timer.join().unwrap();
|
timer.join().unwrap();
|
||||||
|
|
||||||
eprintln!("\r{}ms to calculate the permutations (p) for {} chars (n) across {} slots (r).", start.elapsed().as_millis().to_formatted_string(&Locale::en_NA), char_list.len(), output_len);
|
eprintln!("\r{}ms to calculate the {} permutations (p) for {} chars (n) across {} slots (r).",
|
||||||
|
start.elapsed().as_millis().to_formatted_string(&Locale::en_NA),
|
||||||
|
unsafe {TOTAL}.to_formatted_string(&Locale::en_NA),
|
||||||
|
char_list.len(),
|
||||||
|
output_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let charset = Charset::AllAlpha.as_str();
|
||||||
// All the status messages are printed on stderr
|
// All the status messages are printed on stderr
|
||||||
// This way you can pipe the actual permutations into
|
// This way you can pipe the actual permutations into
|
||||||
// a file whilst still getting debug messages.
|
// a file whilst still getting debug messages.
|
||||||
let t = (ALL_CHARS_95.len() as u128).pow(LEN.try_into().unwrap());
|
let t = (charset.len() as u128).pow(LEN.try_into().unwrap());
|
||||||
unsafe { TOTAL = t as usize };
|
unsafe { TOTAL = t as usize };
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"Calculating {} combinations...\n(Number may be truncated if too large)\n",
|
"\nCalculating {} combinations...\n(Number may be truncated if too large)\n",
|
||||||
unsafe { TOTAL }.to_formatted_string(&Locale::en_NA)
|
unsafe { TOTAL }.to_formatted_string(&Locale::en_NA)
|
||||||
);
|
);
|
||||||
|
|
||||||
start(ALL_CHARS_95, LEN);
|
start(&charset, LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Recursively create and print every combination of
|
/// Recursively create and print every combination of
|
||||||
|
Loading…
Reference in New Issue
Block a user