diff --git a/src/main.rs b/src/main.rs index 10195fb..9a1ce4c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -171,18 +171,15 @@ fn decrypt(_opts: &Opts, args: &Decrypt) { /// Creates a dictionary from an input file and writes it to the output file fn create_dictionary(_opts: &Opts, args: &CreateDictionary) { let input: String = (*args.input).parse().unwrap(); - let contents = fs::read_to_string(input).expect("Failed to read input file!"); - let lines = contents.lines().collect::>(); - let sp = spinner(format!("Parsing {} passwords...", lines.len()).as_str()); - - let pws: Vec = lines - .par_iter() - .map(|s| -> String { s.parse().unwrap() }) - .collect(); - sp.message("Removing duplicates".into()); - let passwords = pws.iter().unique().collect_vec(); - sp.message("Mapping passwords to keys".into()); - let dictionary = map_to_keys(passwords); + let sp = spinner("Parsing passwords..."); + let dictionary: Vec; + { + let pws = get_lines(&input); + sp.message("Removing duplicates".into()); + let passwords = pws.iter().unique().collect_vec(); + sp.message("Mapping passwords to keys".into()); + dictionary = map_to_keys(passwords); + } sp.message("Encoding data to lines".into()); let dict_lines: Vec = dictionary .par_iter() @@ -204,6 +201,15 @@ fn create_dictionary(_opts: &Opts, args: &CreateDictionary) { println!("Finished!"); } +fn get_lines(filename: &str) -> Vec { + let contents = fs::read_to_string(filename).expect("Failed to read input file!"); + let lines = contents.lines().collect::>(); + lines + .par_iter() + .map(|s| -> String { s.parse().unwrap() }) + .collect() +} + /// Creates a new spinner with a given text fn spinner(text: &str) -> Spinner { Spinner::new(Spinners::Dots2, text.into())