put some logic into functions
This commit is contained in:
committed by
Michael Vines
parent
1d32603b49
commit
eacd8d986c
@ -30,6 +30,12 @@ use std::{
|
||||
|
||||
const NO_PASSPHRASE: &str = "";
|
||||
|
||||
struct GrindMatch {
|
||||
starts: String,
|
||||
ends: String,
|
||||
count: AtomicU64,
|
||||
}
|
||||
|
||||
fn check_for_overwrite(outfile: &str, matches: &ArgMatches) {
|
||||
let force = matches.is_present("force");
|
||||
if !force && Path::new(outfile).exists() {
|
||||
@ -123,6 +129,63 @@ fn grind_validator_starts_and_ends_with(v: String) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn grind_print_info(grind_matches: &Vec<GrindMatch>) {
|
||||
println!("Searching with {} threads for:", num_cpus::get());
|
||||
for gm in grind_matches {
|
||||
let mut msg = Vec::<String>::new();
|
||||
if gm.count.load(Ordering::Relaxed) > 1 {
|
||||
msg.push("pubkeys".to_string());
|
||||
msg.push("start".to_string());
|
||||
msg.push("end".to_string());
|
||||
} else {
|
||||
msg.push("pubkey".to_string());
|
||||
msg.push("starts".to_string());
|
||||
msg.push("ends".to_string());
|
||||
}
|
||||
println!(
|
||||
"\t{} {} that {} with '{}' and {} with '{}'",
|
||||
gm.count.load(Ordering::Relaxed),
|
||||
msg[0],
|
||||
msg[1],
|
||||
gm.starts,
|
||||
msg[2],
|
||||
gm.ends
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn grind_parse_args(
|
||||
grind_matches: &mut Vec<GrindMatch>,
|
||||
starts_with_args: HashSet<String>,
|
||||
ends_with_args: HashSet<String>,
|
||||
starts_and_ends_with_args: HashSet<String>,
|
||||
) {
|
||||
for sw in starts_with_args {
|
||||
let args: Vec<&str> = sw.split(':').collect();
|
||||
grind_matches.push(GrindMatch {
|
||||
starts: args[0].to_lowercase(),
|
||||
ends: "".to_string(),
|
||||
count: AtomicU64::new(args[1].parse::<u64>().unwrap()),
|
||||
});
|
||||
}
|
||||
for ew in ends_with_args {
|
||||
let args: Vec<&str> = ew.split(':').collect();
|
||||
grind_matches.push(GrindMatch {
|
||||
starts: "".to_string(),
|
||||
ends: args[0].to_lowercase(),
|
||||
count: AtomicU64::new(args[1].parse::<u64>().unwrap()),
|
||||
});
|
||||
}
|
||||
for swew in starts_and_ends_with_args {
|
||||
let args: Vec<&str> = swew.split(':').collect();
|
||||
grind_matches.push(GrindMatch {
|
||||
starts: args[0].to_lowercase(),
|
||||
ends: args[1].to_lowercase(),
|
||||
count: AtomicU64::new(args[2].parse::<u64>().unwrap()),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn error::Error>> {
|
||||
let matches = App::new(crate_name!())
|
||||
.about(crate_description!())
|
||||
@ -364,12 +427,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||
output_keypair(&keypair, &outfile, "recovered")?;
|
||||
}
|
||||
("grind", Some(matches)) => {
|
||||
struct Match {
|
||||
starts: String,
|
||||
ends: String,
|
||||
count: AtomicU64,
|
||||
}
|
||||
let mut grind_matches = Vec::<Match>::new();
|
||||
let mut grind_matches = Vec::<GrindMatch>::new();
|
||||
|
||||
let ignore_case = matches.is_present("ignore_case");
|
||||
|
||||
@ -408,53 +466,35 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for sw in &starts_with_args {
|
||||
let args: Vec<&str> = sw.split(':').collect();
|
||||
grind_matches.push(Match {
|
||||
starts: args[0].to_lowercase(),
|
||||
ends: "".to_string(),
|
||||
count: AtomicU64::new(args[1].parse::<u64>().unwrap()),
|
||||
});
|
||||
}
|
||||
for ew in &ends_with_args {
|
||||
let args: Vec<&str> = ew.split(':').collect();
|
||||
grind_matches.push(Match {
|
||||
starts: "".to_string(),
|
||||
ends: args[0].to_lowercase(),
|
||||
count: AtomicU64::new(args[1].parse::<u64>().unwrap()),
|
||||
});
|
||||
}
|
||||
for swew in &starts_and_ends_with_args {
|
||||
let args: Vec<&str> = swew.split(':').collect();
|
||||
grind_matches.push(Match {
|
||||
starts: args[0].to_lowercase(),
|
||||
ends: args[1].to_lowercase(),
|
||||
count: AtomicU64::new(args[2].parse::<u64>().unwrap()),
|
||||
});
|
||||
}
|
||||
|
||||
println!("Searching with {} threads for:", num_cpus::get());
|
||||
for gm in &grind_matches {
|
||||
let mut msg = Vec::<String>::new();
|
||||
if gm.count.load(Ordering::Relaxed) > 1 {
|
||||
msg.push("pubkeys".to_string());
|
||||
msg.push("start".to_string());
|
||||
msg.push("end".to_string());
|
||||
} else {
|
||||
msg.push("pubkey".to_string());
|
||||
msg.push("starts".to_string());
|
||||
msg.push("ends".to_string());
|
||||
}
|
||||
println!(
|
||||
"\t{} {} that {} with '{}' and {} with '{}'",
|
||||
gm.count.load(Ordering::Relaxed),
|
||||
msg[0],
|
||||
msg[1],
|
||||
gm.starts,
|
||||
msg[2],
|
||||
gm.ends
|
||||
grind_print_info(&grind_matches);
|
||||
grind_parse_args(
|
||||
&mut grind_matches,
|
||||
starts_with_args,
|
||||
ends_with_args,
|
||||
starts_and_ends_with_args,
|
||||
);
|
||||
}
|
||||
// println!("Searching with {} threads for:", num_cpus::get());
|
||||
// for gm in &grind_matches {
|
||||
// let mut msg = Vec::<String>::new();
|
||||
// if gm.count.load(Ordering::Relaxed) > 1 {
|
||||
// msg.push("pubkeys".to_string());
|
||||
// msg.push("start".to_string());
|
||||
// msg.push("end".to_string());
|
||||
// } else {
|
||||
// msg.push("pubkey".to_string());
|
||||
// msg.push("starts".to_string());
|
||||
// msg.push("ends".to_string());
|
||||
// }
|
||||
// println!(
|
||||
// "\t{} {} that {} with '{}' and {} with '{}'",
|
||||
// gm.count.load(Ordering::Relaxed),
|
||||
// msg[0],
|
||||
// msg[1],
|
||||
// gm.starts,
|
||||
// msg[2],
|
||||
// gm.ends
|
||||
// );
|
||||
// }
|
||||
|
||||
let grind_matches_thread_safe = Arc::new(grind_matches);
|
||||
let attempts = Arc::new(AtomicU64::new(1));
|
||||
|
Reference in New Issue
Block a user