I made this project in my free time to try to crack a 4x hashed md5 with a couple of hints but I'm looking for ways I can optimize this algo because it's pretty slow and I know you could probs use threading or some other ways to increase speed.
If you can even point out some minor ways to increase performance I would be eternally grateful.
I was told I could try re-using the memory for the strings but I'm not sure how to do that. I was also told to not generate the wordlist in advance and try as I go but I dont think the algorithm I used supports that?
Here's the branch to review (more info in the readme): https://github.com/TransmissionsDev/crack_yearn_md5/tree/v1
Here's the main.rs file:
#[cfg(debug_assertions)]
use num_format::{Locale, ToFormattedString};
fn hash_md5(input: String) -> String {
format!("{:x}", md5::compute(input.into_bytes()))
}
fn main() {
let goal_hash = "dbba1bfe930d953cabcc03d7b6ab05e";
let length = 17;
let alphabet = "bdeilmostu-"
.split("")
.map(String::from)
.filter(|letter| !letter.is_empty())
.collect::<Vec<String>>();
let mut words = alphabet.clone();
for phase in 1..length {
let mut temp: Vec<String> = Vec::new();
#[cfg(not(debug_assertions))]
let loopable_words = words.iter();
#[cfg(debug_assertions)]
let loopable_words = words.iter().enumerate();
for data in loopable_words {
#[cfg(not(debug_assertions))]
let word = data;
#[cfg(debug_assertions)]
let word = data.1;
#[cfg(debug_assertions)]
let index = data.0;
for letter in alphabet.iter() {
let new_word = format!("{}{}", word, letter);
temp.push(new_word);
}
#[cfg(debug_assertions)]
if index != 0 && ((index % 1000000) == 0) {
println!(
"Completed phase {}/{}'s sub-phase {}/{}",
phase,
length,
index.to_formatted_string(&Locale::en),
words.len().to_formatted_string(&Locale::en),
);
}
}
words = temp;
}
#[cfg(debug_assertions)]
let word_list_length = words.len();
#[cfg(debug_assertions)]
println!("\n\nLength of word list: {}\n\n", word_list_length);
#[cfg(not(debug_assertions))]
let loopable_words = words.iter();
#[cfg(debug_assertions)]
let loopable_words = words.iter().enumerate();
for data in loopable_words {
#[cfg(not(debug_assertions))]
let word = data;
#[cfg(debug_assertions)]
let word = data.1;
#[cfg(debug_assertions)]
let attempts = data.0;
let merged = format!(
"{}{}",
word, "........................................................!1"
);
let hash = hash_md5(hash_md5(hash_md5(hash_md5(merged.clone()))));
#[cfg(debug_assertions)]
println!(
"Attempts: {}/{}, Hash: {}, Text: {}",
attempts, word_list_length, hash, merged
);
if hash == goal_hash {
println!("We found the password: {}", merged);
return;
}
}
}