Rust implementation...<p>The code searches permutations of increasing length. Benchmark is 8 seconds on a MacBook Pro M1 to discover the match of 182a7c9. The code is not yet optimized.<p><pre><code> use std::time::SystemTime;
use itertools::Itertools;
use sha256::digest;
fn main() {
let digits: [usize; 16] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
let chars = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
let words = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "a", "b", "c", "d", "e", "f"];
let mut length = 2;
let start = SystemTime::now();
loop {
for permutation in digits.iter().permutations(length) {
let parts = permutation.iter().map(|x| words[**x]).collect_vec();
let sentence = format!(
"The SHA256 for this sentence begins with: {} and {}.",
&parts[0..(parts.len() - 1)].join(", "),
&parts[parts.len() - 1]
);
let checksum: String = digest(&sentence);
let starts: String = permutation.iter().map(|x| chars[**x]).collect();
if checksum.starts_with(&starts) {
println!("milliseconds: {:?}, {} ", start.elapsed().unwrap().as_millis(), &sentence);
}
};
length += 1;
}
}
</code></pre>
Output:<p><pre><code> milliseconds: 3, The SHA256 for this sentence begins with: zero, b, six and two.
milliseconds: 54, The SHA256 for this sentence begins with: zero, e, d, eight and f.
milliseconds: 8279, The SHA256 for this sentence begins with: one, eight, two, a, seven, c and nine.
</code></pre>
Repository:<p><a href="https://github.com/joelparkerhenderson/sha256-sentence">https://github.com/joelparkerhenderson/sha256-sentence</a>