Change data to be stored in mutex when encrypting

Change data to be stored in a Mutex when encrypting with a dictionary to avoid decrypting the data twice for a result.
master
trivernis 5 years ago
parent 3e9e1a1eb6
commit ed4391da13

@ -4,6 +4,7 @@ use cfb_mode::Cfb;
use des::Des;
use rand::Rng;
use rayon::prelude::*;
use std::sync::Mutex;
type DesCfb = Cfb<Des>;
@ -35,15 +36,24 @@ pub fn decrypt_with_dictionary(
dict: Vec<PassKey>,
checksum: &[u8],
) -> Option<Vec<u8>> {
let decrypted = Mutex::<Option<Vec<u8>>>::new(None);
let pass = dict.par_iter().find_first(|(_pw, key)| {
let decrypted_data = decrypt_data(&data, key);
let decr_check = sha_checksum(&decrypted_data);
decr_check == checksum
return if decr_check == checksum {
let mut decry = decrypted.lock().unwrap();
*decry = Some(decrypted_data);
true
} else {
false
};
});
if let Some((pw, key)) = pass {
if let Some((pw, _key)) = pass {
println!("Password found: {}", pw);
return Some(decrypt_data(data, &key));
let decry = decrypted.lock().unwrap();
if let Some(decrypted_data) = (*decry).clone() {
return Some(decrypted_data);
}
}
None
}

@ -180,7 +180,7 @@ fn create_dictionary(_opts: &Opts, args: &CreateDictionary) {
println!("Writing passwords to file...");
let mut fout = File::create(args.output.clone()).unwrap();
for entry in dictionary {
for entry in &dictionary {
let key = base64::encode(entry.1.as_slice());
let line = format!("{},{}\n", entry.0, key);
fout.write(&line.into_bytes()).unwrap();

Loading…
Cancel
Save