fix!: remove rust-crypto
This commit is contained in:
@@ -1,40 +1,32 @@
|
||||
use crypto::digest::Digest;
|
||||
use crypto::md5::Md5;
|
||||
use md5::{Digest, Md5};
|
||||
|
||||
pub fn part_one(input: &str) -> Option<u32> {
|
||||
let key = input.trim().as_bytes();
|
||||
let mut hasher = Md5::new();
|
||||
for x in 0..std::u64::MAX {
|
||||
hasher.input(key);
|
||||
hasher.input(x.to_string().as_bytes());
|
||||
hasher.update(key);
|
||||
hasher.update(x.to_string().as_bytes());
|
||||
let output = hasher.finalize_reset();
|
||||
|
||||
let mut output = [0; 16];
|
||||
hasher.result(&mut output);
|
||||
|
||||
let first_five = output[0] as u32 + output[1] as u32 + (output[2] >> 4) as u32;
|
||||
if first_five == 0 {
|
||||
if output.starts_with(&[0, 0]) && output[2] <= 0x0F {
|
||||
return Some(x as u32);
|
||||
}
|
||||
hasher.reset();
|
||||
}
|
||||
None
|
||||
unreachable!()
|
||||
}
|
||||
pub fn part_two(input: &str) -> Option<u32> {
|
||||
let key = input.trim().as_bytes();
|
||||
let mut hasher = Md5::new();
|
||||
for x in 0..std::u64::MAX {
|
||||
hasher.input(key);
|
||||
hasher.input(x.to_string().as_bytes());
|
||||
|
||||
let mut output = [0; 16];
|
||||
hasher.result(&mut output);
|
||||
hasher.update(key);
|
||||
hasher.update(x.to_string().as_bytes());
|
||||
let output = hasher.finalize_reset();
|
||||
|
||||
if output.starts_with(&[0, 0, 0]) {
|
||||
return Some(x as u32);
|
||||
}
|
||||
hasher.reset();
|
||||
}
|
||||
None
|
||||
unreachable!()
|
||||
}
|
||||
fn main() {
|
||||
let input = &aoc::read_file("inputs", 4);
|
||||
|
Reference in New Issue
Block a user