Skip to content

Instantly share code, notes, and snippets.

@lnds
Created December 7, 2019 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lnds/44b4d7b2cb439272b3829138ba1beb47 to your computer and use it in GitHub Desktop.
Save lnds/44b4d7b2cb439272b3829138ba1beb47 to your computer and use it in GitHub Desktop.
// Sha512 in Rust
#[macro_use]
extern crate itertools;
use sha2::{Digest, Sha512};
fn main() {
let target = Sha512::new().chain(b"help").result();
let alpha = "abcdefghijklmnopqrstuvwxyz";
let col = iproduct!(alpha.chars(), alpha.chars(), alpha.chars(), alpha.chars())
.map(|(a, b, c, d)| format!("{}{}{}{}", a, b, c, d))
.filter(|candidate| Sha512::new().chain(&candidate).result() == target)
.collect::<Vec<String>>();
println!("{:?}", col);
}
// time cargo run --release
// real 0m0.304s
// user 0m0.284s
// sys 0m0.015s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment