fn create_dictionary(_opts: &Opts, args: &CreateDictionary) {
    let mut tt = TimeTaker::new();
    tt.take("start");
    let sp = spinner("Reading input file...");
    let input: String = (*args.input).parse().unwrap();
    // TODO: Some form of removing duplicates (without itertools)
    let fout = File::create(args.output.clone()).unwrap();

    let content = fs::read_to_string(input).expect("Failed to read content");
    let lines = content.par_lines();
    let entry_count = lines.clone().count() as u64;
    sp.stop();

    let mut pb = ProgressBar::new(entry_count);
    pb.set_max_refresh_rate(Some(Duration::from_millis(200)));

    let mut bdf_file = BDFWriter::new(fout, entry_count, args.compress != 0);
    bdf_file.set_compression_level(args.compress);
    bdf_file
        .set_entries_per_chunk(args.entries_per_chunk)
        .expect("Failed to set the entries per chunk.");
    bdf_file
        .add_lookup_entry(HashEntry::new(SHA256.to_string(), 32))
        .expect("Failed to add sha256 lookup entry");

    let mut threads = Vec::new();
    let (rx, tx) = bounded::<DataEntry>(100_00_000);
    let bdf_arc = Arc::new(Mutex::new(bdf_file));
    let pb_arc = Arc::new(Mutex::new(pb));

    for _ in 0..(num_cpus::get() as f32 / 4f32).max(1f32) as usize {
        let tx = tx.clone();
        let bdf_arc = Arc::clone(&bdf_arc);
        let pb_arc = Arc::clone(&pb_arc);
        threads.push(thread::spawn(move || {
            for entry in tx {
                if let Err(e) = &bdf_arc.lock().unwrap().add_data_entry(entry) {
                    println!("{:?}", e);
                }
                pb_arc.lock().unwrap().inc();
            }
        }));
    }

    tt.take("creation");
    let re = Regex::new("[\\x00\\x08\\x0B\\x0C\\x0E-\\x1F\\t\\r\\a\\n]").unwrap();
    lines
        .map(|line| -> String { re.replace_all(line, "").to_string() })
        .map(|pw| -> DataEntry {
            let key256 = sha256(&pw);
            let mut data_entry = DataEntry::new(pw);
            data_entry.add_hash_value(SHA256.to_string(), key256);

            data_entry
        })
        .for_each_with(rx, |rx, data_entry| {
            rx.send(data_entry)
                .expect("Failed to send value to channel.");
        });

    for handle in threads {
        if let Err(_err) = handle.join() {
            println!("Failed to join!");
        }
    }
    bdf_arc
        .lock()
        .unwrap()
        .finish()
        .expect("failed to finish the writing process");
    pb_arc.lock().unwrap().finish();
    println!(
        "Rainbow table creation took {:.2}s",
        tt.since("creation").unwrap().as_secs_f32()
    );
    println!("Finished {:.2}s!", tt.since("start").unwrap().as_secs_f32());
}
/// Creates a dictionary from an input file and writes it to the output file
Creates a dictionary from an input file and writes it to the output file
Creates a dictionary from an input file and writes it to the output file
fn create_dictionary(_opts: &Opts, args: &CreateDictionary) {
    let mut tt = TimeTaker::new();
    tt.take("start");
    let sp = spinner("Reading input file...");
    let input: String = (*args.input).parse().unwrap();
    // TODO: Some form of removing duplicates (without itertools)
    let fout = File::create(args.output.clone()).unwrap();
    let content = fs::read_to_string(input).expect("Failed to read content");
    let lines = content.par_lines();
    let entry_count = lines.clone().count() as u64;
    sp.stop();
    let mut pb = ProgressBar::new(entry_count);
    pb.set_max_refresh_rate(Some(Duration::from_millis(200)));
    let mut bdf_file = BDFWriter::new(fout, entry_count, args.compress != 0);
    bdf_file.set_compression_level(args.compress);
    bdf_file
        .set_entries_per_chunk(args.entries_per_chunk)
        .expect("Failed to set the entries per chunk.");
    bdf_file
        .add_lookup_entry(HashEntry::new(SHA256.to_string(), 32))
        .expect("Failed to add sha256 lookup entry");
    let mut threads = Vec::new();
    let (rx, tx) = bounded::<DataEntry>(100_00_000);
    let bdf_arc = Arc::new(Mutex::new(bdf_file));
    let pb_arc = Arc::new(Mutex::new(pb));
    for _ in 0..(num_cpus::get() as f32 / 4f32).max(1f32) as usize {
        let tx = tx.clone();
        let bdf_arc = Arc::clone(&bdf_arc);
        let pb_arc = Arc::clone(&pb_arc);
        threads.push(thread::spawn(move || {
            for entry in tx {
                if let Err(e) = &bdf_arc.lock().unwrap().add_data_entry(entry) {
                    println!("{:?}", e);
                }
                pb_arc.lock().unwrap().inc();
            }
        }));
    }
    tt.take("creation");
    let re = Regex::new("[\\x00\\x08\\x0B\\x0C\\x0E-\\x1F\\t\\r\\a\\n]").unwrap();
    lines
        .map(|line| -> String { re.replace_all(line, "").to_string() })
        .map(|pw| -> DataEntry {
            let key256 = sha256(&pw);
            let mut data_entry = DataEntry::new(pw);
            data_entry.add_hash_value(SHA256.to_string(), key256);
            data_entry
        })
        .for_each_with(rx, |rx, data_entry| {
            rx.send(data_entry)
                .expect("Failed to send value to channel.");
        });
    for handle in threads {
        if let Err(_err) = handle.join() {
            println!("Failed to join!");
        }
    }
    bdf_arc
        .lock()
        .unwrap()
        .finish()
        .expect("failed to finish the writing process");
    pb_arc.lock().unwrap().finish();
    println!(
        "Rainbow table creation took {:.2}s",
        tt.since("creation").unwrap().as_secs_f32()
    );
    println!("Finished {:.2}s!", tt.since("start").unwrap().as_secs_f32());
}
fn create_dictionary ( _opts : & Opts , args : & CreateDictionary ) { let mut tt = TimeTaker :: new ( ) ; tt . take ( " " ) ; let sp = spinner ( " " ) ; let input : String = ( * args . input ) . parse ( ) . unwrap ( ) ; // TODO: Some form of removing duplicates (without itertools) let fout = File :: create ( args . output . clone ( ) ) . unwrap ( ) ; let content = fs :: read_to_string ( input ) . expect ( " " ) ; let lines = content . par_lines ( ) ; let entry_count = lines . clone ( ) . count ( ) as u64 ; sp . stop ( ) ; let mut pb = ProgressBar :: new ( entry_count ) ; pb . set_max_refresh_rate ( Some ( Duration :: from_millis ( 200 ) ) ) ; let mut bdf_file = BDFWriter :: new ( fout , entry_count , args . compress != 0 ) ; bdf_file . set_compression_level ( args . compress ) ; bdf_file . set_entries_per_chunk ( args . entries_per_chunk ) . expect ( " " ) ; bdf_file . add_lookup_entry ( HashEntry :: new ( SHA256 . to_string ( ) , 32 ) ) . expect ( " " ) ; let mut threads = Vec :: new ( ) ; let ( rx , tx ) = bounded :: < DataEntry > ( 100_00_000 ) ; let bdf_arc = Arc :: new ( Mutex :: new ( bdf_file ) ) ; let pb_arc = Arc :: new ( Mutex :: new ( pb ) ) ; for _ in 0 .. ( num_cpus :: get ( ) as f32 / 4f32 ) . max ( 1f32 ) as usize { let tx = tx . clone ( ) ; let bdf_arc = Arc :: clone ( & bdf_arc ) ; let pb_arc = Arc :: clone ( & pb_arc ) ; threads . push ( thread :: spawn ( move | | { for entry in tx { if let Err ( e ) = & bdf_arc . lock ( ) . unwrap ( ) . add_data_entry ( entry ) { println ! ( " " e ) ; } pb_arc . lock ( ) . unwrap ( ) . inc ( ) ; } } ) ) ; } tt . take ( " " ) ; let re = Regex :: new ( " \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ " ) . unwrap ( ) ; lines . map ( | line | -> String { re . replace_all ( line , " " ) . to_string ( ) } ) . map ( | pw | -> DataEntry { let key256 = sha256 ( & pw ) ; let mut data_entry = DataEntry :: new ( pw ) ; data_entry . add_hash_value ( SHA256 . to_string ( ) , key256 ) ; data_entry } ) . for_each_with ( rx , | rx , data_entry | { rx . send ( data_entry ) . expect ( " " ) ; } ) ; for handle in threads { if let Err ( _err ) = handle . join ( ) { println ! ( " " ) ; } } bdf_arc . lock ( ) . unwrap ( ) . finish ( ) . expect ( " " ) ; pb_arc . lock ( ) . unwrap ( ) . finish ( ) ; println ! ( " " tt since ( " " ) unwrap ( ) as_secs_f32 ( ) ) ; println ! ( " " tt since ( " " ) unwrap ( ) as_secs_f32 ( ) ) ; }
Creates a dictionary from an input file and writes it to the output file
Creates a dictionary from an input file and writes it to the output file
_opts
&Opts
args
&CreateDictionary