Created
February 27, 2019 19:34
-
-
Save roblabla/6bb6d2dd91aae2ef3c4865440539c41c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use rand::Rng; | |
use sha2::Digest; | |
use rayon::prelude::*; | |
fn main() { | |
let spinner = indicatif::ProgressBar::new_spinner(); | |
spinner.set_draw_target(indicatif::ProgressDrawTarget::stdout()); | |
spinner.set_style(indicatif::ProgressStyle::default_spinner().template("[{elapsed_precise}] {pos:>7} {spinner} {msg}")); | |
loop { | |
let s = rand::thread_rng() | |
.sample_iter::<char, _>(&rand::distributions::Standard) | |
.take(30) | |
.collect::<String>(); | |
let hash = sha2::Sha256::digest(s.as_bytes()); | |
if hash.as_slice().par_iter().all(u8::is_ascii_graphic) { | |
println!("Str: {}", s); | |
println!("Hash: {:?}", hash); | |
spinner.finish_with_message(&*s); | |
break; | |
} else { | |
spinner.inc(1); | |
spinner.set_message(&*s); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment