From d2eccf2affd1f44d26b9784a2bfadebf3cfd5046 Mon Sep 17 00:00:00 2001 From: trivernis Date: Wed, 19 Feb 2020 23:49:16 +0100 Subject: [PATCH] Code Cleanup --- src/lib/crypt.rs | 2 ++ src/main.rs | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/lib/crypt.rs b/src/lib/crypt.rs index 492a879..736b78b 100644 --- a/src/lib/crypt.rs +++ b/src/lib/crypt.rs @@ -58,6 +58,7 @@ pub fn decrypt_with_dictionary(data: &[u8], dict: Vec, checksum: &[u8]) let pass = dict.par_iter().find_first(|(_pw, key)| { let decrypted_data = decrypt_data(&data, key); let decr_check = sha_checksum(&decrypted_data); + if decr_check == checksum { true } else { @@ -78,6 +79,7 @@ pub fn decrypt_brute_brute_force(data: &[u8], checksum: &[u8]) -> Option let key: &[u8] = &num.to_le_bytes(); let decrypted_data = decrypt_data(&data, key); let decr_check = sha_checksum(&decrypted_data); + if decr_check == checksum { true } else { diff --git a/src/main.rs b/src/main.rs index 9a2534d..af10b67 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,6 +93,7 @@ fn encrypt(_opts: &Opts, args: &Encrypt) { let input = (*args.input).parse().unwrap(); let output = (*args.output).parse().unwrap(); let data: Vec = read_file_binary(input); + if let Some(output_checksum) = (args.clone()).output_checksum { let checksum = sha_checksum(&data); let checksum_b64 = base64::encode(checksum.as_slice()); @@ -115,10 +116,12 @@ fn decrypt(_opts: &Opts, args: &Decrypt) { if let Some(input_checksum) = (args.clone()).input_checksum { let bin_content = read_file_binary(input_checksum); let data_checksum = base64::decode(bin_content.as_slice()).unwrap(); + if let Some(dict) = dictionary { println!("Reading dictionary..."); let dictionary = read_file(dict); let lines = dictionary.lines().collect::>(); + let pw_table: Vec = lines.par_iter().map(|line| { let parts: Vec<&str> = line.split(",").collect::>(); let pw = parts[0].parse().unwrap(); @@ -126,6 +129,7 @@ fn decrypt(_opts: &Opts, args: &Decrypt) { let key = base64::decode(&key_str).unwrap(); (pw, key) }).collect(); + println!("Starting multithreaded decryption..."); if let Some(dec_data) = decrypt_with_dictionary(&data, pw_table, &data_checksum) { write_file(output, &dec_data); @@ -156,6 +160,7 @@ fn create_dictionary(_opts: &Opts, args: &CreateDictionary) { let contents = read_file(input); let lines = contents.lines().collect::>(); println!("Parsing {} passwords...", lines.len()); + let pws: Vec = lines.par_iter().map(| s | -> String { s.parse().unwrap() }).collect(); @@ -165,6 +170,7 @@ fn create_dictionary(_opts: &Opts, args: &CreateDictionary) { let dictionary = map_to_keys(passwords); println!("Writing passwords to file..."); let mut fout = File::create(args.output.clone()).unwrap(); + for entry in dictionary.iter() { let key = base64::encode((*entry).1.as_slice()); let line = format!("{},{}\n", (*entry).0, key);