This commit is contained in:
2016-12-01 14:46:14 +01:00
parent e5af2023c2
commit fb1cae4339
3 changed files with 136 additions and 0 deletions

48
2015/04/src/main.rs Normal file
View File

@@ -0,0 +1,48 @@
extern crate crypto;
use std::u64;
use crypto::md5::Md5;
use crypto::digest::Digest;
fn main() {
println!("{:?}", process("ckczppom", "000000"));
}
fn process(secret: &str, starts_with: &str) -> Option<u64> {
let mut md5 = Md5::new();
for i in 1..u64::MAX {
let input = format!("{}{}", secret, i);
md5.input(input.as_bytes());
let result = md5.result_str();
if result.starts_with(starts_with) {
return Some(i);
}
md5.reset();
}
None
}
#[cfg(test)]
mod tests {
use super::process;
#[test]
fn example_01() {
assert_eq!(Some(609043), process("abcdef", "00000"));
}
#[test]
fn example_02() {
assert_eq!(Some(1048970), process("pqrstuv", "00000"));
}
}