My QQ number Rust quiz
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
// https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3a2c2557cb1b7d0a313c1e011ba16844 | |
use rand::prelude::*; | |
fn main() { | |
let mut rng = SmallRng::from_seed([0x56u8; 32]); | |
(0..10).for_each(|_| (rng.next_u32(), ()).1); | |
let key: [u8; 20] = [ | |
70, 121, 148, 150, 158, 158, 73, 14, 197, 164, 232, 30, 239, 6, 112, 10, 130, 30, 55, 173, | |
]; | |
let mut bytes = [0; 20]; | |
rng.fill_bytes(&bytes); | |
for b in 0..20 { | |
bytes[b] = key[b].wrapping_sub(bytes[b]); | |
} | |
assert_eq!(&bytes[15..], &[0; 5], "Invalid key"); | |
let nums = &bytes[1..(bytes[0] as usize)]; | |
println!( | |
"{}", | |
nums.iter() | |
.map(|n| n.to_string()) | |
.collect::<Vec<_>>() | |
.join("") | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bdbai commentedDec 5, 2021