fn decrypt_with_dictionary_file(filename: String, data: &Vec<u8>) -> Option<Vec<u8>> {
    let sp = spinner("Reading dictionary...");
    let f = File::open(&filename).expect("Failed to open dictionary file.");
    let mut bdf_file = BDFReader::new(f);
    bdf_file.read_start().expect("failed to read the bdf file");
    let mut chunk_count = 0;
    if let Some(meta) = &bdf_file.metadata {
        chunk_count = meta.chunk_count;
    }
    let mut pb = ProgressBar::new(chunk_count as u64);
    let bdf_arc = Arc::new(Mutex::new(bdf_file));
    let mut threads = Vec::new();
    let (rx, tx) = bounded::<Vec<DataEntry>>(100);

    for _ in 0..(num_cpus::get() as f32 / 4f32).max(1f32) as usize {
        let rx = rx.clone();
        let bdf_arc = Arc::clone(&bdf_arc);

        threads.push(thread::spawn(move || {
            let mut lookup_table = HashLookupTable::new(HashMap::new());
            if let Some(table) = &bdf_arc.lock().unwrap().lookup_table {
                lookup_table = table.clone();
            }
            while let Ok(next_chunk) = &mut bdf_arc
                .lock()
                .expect("failed to lock bdf_arc to read next chunk")
                .next_chunk()
            {
                if let Ok(entries) = next_chunk.data_entries(&lookup_table) {
                    if let Err(_) = rx.send(entries) {}
                }
            }
        }));
    }
    drop(rx);
    sp.stop();
    let mut result_data: Option<Vec<u8>> = None;
    for entries in tx {
        let pw_table: Vec<(&String, &Vec<u8>)> = entries
            .par_iter()
            .map(|entry: &DataEntry| {
                let pw = &entry.plain;
                let key: &Vec<u8> = entry.get_hash_value(SHA256.to_string()).unwrap();

                (pw, key)
            })
            .collect();
        pb.inc();
        if let Some(dec_data) = decrypt_with_dictionary(&data, pw_table) {
            result_data = Some(dec_data);
            break;
        }
    }
    pb.finish();
    result_data
}
/// Decrypts the file using a bdf dictionary
/// The files content is read chunk by chunk to reduce the memory impact since dictionary
/// files tend to be several gigabytes in size
Decrypts the file using a bdf dictionary
The files content is read chunk by chunk to reduce the memory impact since dictionary
files tend to be several gigabytes in size
Decrypts the file using a bdf dictionary The files content is read chunk by chunk to reduce the memory impact since dictionary files tend to be several gigabytes in size
fn decrypt_with_dictionary_file(filename: String, data: &Vec<u8>) -> Option<Vec<u8>> {
    let sp = spinner("Reading dictionary...");
    let f = File::open(&filename).expect("Failed to open dictionary file.");
    let mut bdf_file = BDFReader::new(f);
    bdf_file.read_start().expect("failed to read the bdf file");
    let mut chunk_count = 0;
    if let Some(meta) = &bdf_file.metadata {
        chunk_count = meta.chunk_count;
    }
    let mut pb = ProgressBar::new(chunk_count as u64);
    let bdf_arc = Arc::new(Mutex::new(bdf_file));
    let mut threads = Vec::new();
    let (rx, tx) = bounded::<Vec<DataEntry>>(100);
    for _ in 0..(num_cpus::get() as f32 / 4f32).max(1f32) as usize {
        let rx = rx.clone();
        let bdf_arc = Arc::clone(&bdf_arc);
        threads.push(thread::spawn(move || {
            let mut lookup_table = HashLookupTable::new(HashMap::new());
            if let Some(table) = &bdf_arc.lock().unwrap().lookup_table {
                lookup_table = table.clone();
            }
            while let Ok(next_chunk) = &mut bdf_arc
                .lock()
                .expect("failed to lock bdf_arc to read next chunk")
                .next_chunk()
            {
                if let Ok(entries) = next_chunk.data_entries(&lookup_table) {
                    if let Err(_) = rx.send(entries) {}
                }
            }
        }));
    }
    drop(rx);
    sp.stop();
    let mut result_data: Option<Vec<u8>> = None;
    for entries in tx {
        let pw_table: Vec<(&String, &Vec<u8>)> = entries
            .par_iter()
            .map(|entry: &DataEntry| {
                let pw = &entry.plain;
                let key: &Vec<u8> = entry.get_hash_value(SHA256.to_string()).unwrap();
                (pw, key)
            })
            .collect();
        pb.inc();
        if let Some(dec_data) = decrypt_with_dictionary(&data, pw_table) {
            result_data = Some(dec_data);
            break;
        }
    }
    pb.finish();
    result_data
}
fn decrypt_with_dictionary_file ( filename : String , data : & Vec < u8 > ) -> Option < Vec < u8 > > { let sp = spinner ( " " ) ; let f = File :: open ( & filename ) . expect ( " " ) ; let mut bdf_file = BDFReader :: new ( f ) ; bdf_file . read_start ( ) . expect ( " " ) ; let mut chunk_count = 0 ; if let Some ( meta ) = & bdf_file . metadata { chunk_count = meta . chunk_count ; } let mut pb = ProgressBar :: new ( chunk_count as u64 ) ; let bdf_arc = Arc :: new ( Mutex :: new ( bdf_file ) ) ; let mut threads = Vec :: new ( ) ; let ( rx , tx ) = bounded :: < Vec < DataEntry > > ( 100 ) ; for _ in 0 .. ( num_cpus :: get ( ) as f32 / 4f32 ) . max ( 1f32 ) as usize { let rx = rx . clone ( ) ; let bdf_arc = Arc :: clone ( & bdf_arc ) ; threads . push ( thread :: spawn ( move | | { let mut lookup_table = HashLookupTable :: new ( HashMap :: new ( ) ) ; if let Some ( table ) = & bdf_arc . lock ( ) . unwrap ( ) . lookup_table { lookup_table = table . clone ( ) ; } while let Ok ( next_chunk ) = & mut bdf_arc . lock ( ) . expect ( " " ) . next_chunk ( ) { if let Ok ( entries ) = next_chunk . data_entries ( & lookup_table ) { if let Err ( _ ) = rx . send ( entries ) { } } } } ) ) ; } drop ( rx ) ; sp . stop ( ) ; let mut result_data : Option < Vec < u8 > > = None ; for entries in tx { let pw_table : Vec < ( & String , & Vec < u8 > ) > = entries . par_iter ( ) . map ( | entry : & DataEntry | { let pw = & entry . plain ; let key : & Vec < u8 > = entry . get_hash_value ( SHA256 . to_string ( ) ) . unwrap ( ) ; ( pw , key ) } ) . collect ( ) ; pb . inc ( ) ; if let Some ( dec_data ) = decrypt_with_dictionary ( & data , pw_table ) { result_data = Some ( dec_data ) ; break ; } } pb . finish ( ) ; result_data }
Decrypts the file using a bdf dictionary
The files content is read chunk by chunk to reduce the memory impact since dictionary
files tend to be several gigabytes in size
Decrypts the file using a bdf dictionary The files content is read chunk by chunk to reduce the memory impact since dictionary files tend to be several gigabytes in size
filename
String
data
&Vec<u8>