From 7ac00d911b1393e4b5c82b74769996733c3bec1a Mon Sep 17 00:00:00 2001 From: Trivernis Date: Tue, 10 Mar 2020 12:41:52 +0100 Subject: [PATCH] Improve memory efficientcy of decryption --- src/main.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index a428904..ffd4a42 100644 --- a/src/main.rs +++ b/src/main.rs @@ -129,19 +129,21 @@ fn decrypt(_opts: &Opts, args: &Decrypt) { if let Some(dict) = dictionary { let sp = spinner("Reading dictionary..."); - let dictionary = fs::read_to_string(dict).expect("Failed to read dictionary file!"); - let lines = dictionary.par_lines(); - - let pw_table: Vec = lines - .map(|line| { - let parts: Vec<&str> = line.split("\t").collect::>(); - let pw = parts[0].parse().unwrap(); - let key_str: String = parts[1].parse().unwrap(); - let key = base64::decode(&key_str).unwrap(); - - (pw, key) - }) - .collect(); + let pw_table: Vec; + { + let dictionary = fs::read_to_string(dict).expect("Failed to read dictionary file!"); + let lines = dictionary.par_lines(); + pw_table = lines + .map(|line| { + let parts: Vec<&str> = line.split("\t").collect::>(); + let pw = parts[0].to_string(); + let key_str: String = parts[1].to_string(); + let key = base64::decode(&key_str).unwrap(); + + (pw, key) + }) + .collect(); + } sp.message("Dictionary decrypting file multithreaded".into()); if let Some(dec_data) = decrypt_with_dictionary(&data, pw_table, &data_checksum) { sp.stop();