blob: a860e53831bddf6c306e9506c62cde8e8f802c2a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
extern crate crypto;
use std::io::{self, Read};
use crypto::digest::Digest;
use crypto::md5::Md5;
fn solve(input: &str) -> String {
let mut password = String::new();
let mut index = 0u64;
while password.len() < 8 {
let mut md5 = Md5::new();
md5.input_str(input);
md5.input_str(&index.to_string());
let digest = md5.result_str();
if &digest[0..5] == "00000" {
password.push_str(&digest[5..6]);
}
index += 1;
}
password
}
fn main() {
let mut input = String::new();
io::stdin().read_to_string(&mut input).unwrap();
println!("Part 1: {}", solve(input.trim()));
}
#[test]
#[ignore]
fn part1() {
assert_eq!("18f47a30", solve("abc"));
}
|