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

@ -9,18 +9,19 @@ pub fn create_key(pw: String) -> Vec<u8> {
hasher.input(pw); hasher.input(pw);
let result = hasher.result(); let result = hasher.result();
let key = &result[0..8]; 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 /// Maps a list of passwords to keys and returns a vector of pairs
pub fn map_to_keys(passwords: Vec<&String>) -> Vec<PassKey> { pub fn map_to_keys(passwords: Vec<&String>) -> Vec<PassKey> {
return passwords passwords
.par_iter() .par_iter()
.map(|pw| { .map(|pw| {
let pw_str = (*pw).clone(); let pw_str = (*pw).clone();
(pw_str.clone(), create_key(pw_str)) (pw_str.clone(), create_key(pw_str))
}) })
.collect(); .collect()
} }
/// Creates a sha256 hashsum from the input data /// 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(); let mut hasher = Sha256::default();
hasher.input(data); hasher.input(data);
let result = hasher.result(); 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 pw = parts[0].parse().unwrap();
let key_str: String = parts[1].parse().unwrap(); let key_str: String = parts[1].parse().unwrap();
let key = base64::decode(&key_str).unwrap(); let key = base64::decode(&key_str).unwrap();
(pw, key) (pw, key)
}) })
.collect(); .collect();
@ -190,7 +191,7 @@ fn read_file_binary(filename: String) -> Vec<u8> {
let mut fin = File::open(filename).unwrap(); let mut fin = File::open(filename).unwrap();
let mut data: Vec<u8> = vec![]; let mut data: Vec<u8> = vec![];
fin.read_to_end(&mut data).unwrap(); fin.read_to_end(&mut data).unwrap();
return data; data
} }
/// Reads a file to the end and returns the contents as a string /// 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 fin = File::open(filename).unwrap();
let mut contents = String::new(); let mut contents = String::new();
fin.read_to_string(&mut contents).unwrap(); fin.read_to_string(&mut contents).unwrap();
return contents; contents
} }
/// writes binary data to a file /// writes binary data to a file

Loading…
Cancel
Save