Add duration output after encryption

master
Trivernis 5 years ago
parent 7ac00d911b
commit dd781209ff

@ -5,6 +5,7 @@ use des::Des;
use rand::Rng; use rand::Rng;
use rayon::prelude::*; use rayon::prelude::*;
use std::sync::Mutex; use std::sync::Mutex;
use std::time::Instant;
type DesCfb = Cfb<Des>; type DesCfb = Cfb<Des>;
@ -37,6 +38,7 @@ pub fn decrypt_with_dictionary(
checksum: &[u8], checksum: &[u8],
) -> Option<Vec<u8>> { ) -> Option<Vec<u8>> {
let decrypted = Mutex::<Option<Vec<u8>>>::new(None); let decrypted = Mutex::<Option<Vec<u8>>>::new(None);
let start = Instant::now();
let pass = dict.par_iter().find_first(|(_pw, key)| { let pass = dict.par_iter().find_first(|(_pw, key)| {
let decrypted_data = decrypt_data(&data, key); let decrypted_data = decrypt_data(&data, key);
let decr_check = sha_checksum(&decrypted_data); let decr_check = sha_checksum(&decrypted_data);
@ -49,7 +51,11 @@ pub fn decrypt_with_dictionary(
}; };
}); });
if let Some((pw, _key)) = pass { if let Some((pw, _key)) = pass {
println!("\nPassword found: {}", pw); println!(
"\nPassword found in {:.2}s: {}",
start.elapsed().as_secs_f32(),
pw
);
let decry = decrypted.lock().unwrap(); let decry = decrypted.lock().unwrap();
if let Some(decrypted_data) = (*decry).clone() { if let Some(decrypted_data) = (*decry).clone() {
return Some(decrypted_data); return Some(decrypted_data);

Loading…
Cancel
Save