Cleanup Code

master
trivernis 5 years ago
parent ca6cb3b21d
commit 5b2632d792

@ -39,7 +39,8 @@ pub fn encrypt_data(data: &[u8], key: &[u8]) -> Vec<u8> {
cipher.encrypt(&mut buffer);
let mut cipher_text = iv.to_vec();
cipher_text.append(&mut buffer.to_vec());
return cipher_text;
cipher_text
}
/// Decrypts data with des
@ -48,7 +49,8 @@ pub fn decrypt_data(data: &[u8], key: &[u8]) -> Vec<u8> {
let mut buffer = data[8..].to_vec();
let mut cipher = DesCfb::new_var(&key, &iv).unwrap();
cipher.decrypt(&mut buffer);
return buffer;
buffer
}
/// Decrypts data using a dictionary
@ -61,11 +63,7 @@ pub fn decrypt_with_dictionary(
let decrypted_data = decrypt_data(&data, key);
let decr_check = sha_checksum(&decrypted_data);
if decr_check == checksum {
true
} else {
false
}
decr_check == checksum
});
if let Some((pw, key)) = pass {
println!("Password found: {}", pw);
@ -84,15 +82,12 @@ pub fn decrypt_brute_brute_force(data: &[u8], checksum: &[u8]) -> Option<Vec<u8>
let decrypted_data = decrypt_data(&data, key);
let decr_check = sha_checksum(&decrypted_data);
if decr_check == checksum {
true
} else {
false
}
decr_check == checksum
});
if let Some(num) = encryption_key {
let key: &[u8] = &num.to_le_bytes();
println!("Key found: {:?}", key);
Some(decrypt_data(data, key))
} else {
None

@ -9,18 +9,19 @@ pub fn create_key(pw: String) -> Vec<u8> {
hasher.input(pw);
let result = hasher.result();
let key = &result[0..8];
return key.to_vec();
key.to_vec()
}
/// Maps a list of passwords to keys and returns a vector of pairs
pub fn map_to_keys(passwords: Vec<&String>) -> Vec<PassKey> {
return passwords
passwords
.par_iter()
.map(|pw| {
let pw_str = (*pw).clone();
(pw_str.clone(), create_key(pw_str))
})
.collect();
.collect()
}
/// Creates a sha256 hashsum from the input data
@ -28,5 +29,6 @@ pub fn sha_checksum(data: &Vec<u8>) -> Vec<u8> {
let mut hasher = Sha256::default();
hasher.input(data);
let result = hasher.result();
return result.to_vec();
result.to_vec()
}

@ -131,6 +131,7 @@ fn decrypt(_opts: &Opts, args: &Decrypt) {
let pw = parts[0].parse().unwrap();
let key_str: String = parts[1].parse().unwrap();
let key = base64::decode(&key_str).unwrap();
(pw, key)
})
.collect();
@ -190,7 +191,7 @@ fn read_file_binary(filename: String) -> Vec<u8> {
let mut fin = File::open(filename).unwrap();
let mut data: Vec<u8> = vec![];
fin.read_to_end(&mut data).unwrap();
return data;
data
}
/// Reads a file to the end and returns the contents as a string
@ -198,7 +199,7 @@ fn read_file(filename: String) -> String {
let mut fin = File::open(filename).unwrap();
let mut contents = String::new();
fin.read_to_string(&mut contents).unwrap();
return contents;
contents
}
/// writes binary data to a file

Loading…
Cancel
Save