Solve challenge 32 and with that problem set 4

This commit is contained in:
2022-08-28 19:48:36 -04:00
parent f50197e480
commit ddafb43934
4 changed files with 104 additions and 61 deletions

View File

@@ -116,7 +116,6 @@ pub fn challenge18() {
println!("[okay] Challenge 18: {cleartext}");
}
mod challenge19 {
use crate::bytes::Bytes;
use std::cell::RefCell;
@@ -232,7 +231,6 @@ mod challenge19 {
deciphered
}
}
pub fn challenge19() {
@@ -313,6 +311,18 @@ pub fn challenge21() {
}
pub fn challenge22() {
fn find_seed(rngout: u32) -> Option<u32> {
let mut mt = mt19937::MT19937::new();
let start = utils::unix_timestamp() - 2000;
for seed in start..(start + 4000) {
mt.seed(seed);
if rngout == mt.extract_number() {
return Some(seed);
}
}
None
}
// Wait a random number of seconds between, I don't know, 40 and 1000.
let now = utils::unix_timestamp();
let wait_time: u32 = rand::thread_rng().gen_range(40..1000);
@@ -326,18 +336,6 @@ pub fn challenge22() {
let rngout = mt.extract_number();
// From the 32 bit RNG output, discover the seed.
fn find_seed(rngout: u32) -> Option<u32> {
let mut mt = mt19937::MT19937::new();
let start = utils::unix_timestamp() - 2000;
for seed in start..(start + 4000) {
mt.seed(seed);
if rngout == mt.extract_number() {
return Some(seed);
}
}
None
}
let found_seed = find_seed(rngout);
assert_eq!(seed, found_seed.unwrap());