fix!: remove rust-crypto

This commit is contained in:
2022-12-04 23:16:22 +01:00
parent 00000220a6
commit 0000023087
3 changed files with 64 additions and 113 deletions

View File

@@ -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);