Skip to content

Instantly share code, notes, and snippets.

Created December 16, 2017 09:55
Show Gist options
  • Save anonymous/852da22e4d63c009a51b24f3a73c515f to your computer and use it in GitHub Desktop.
Save anonymous/852da22e4d63c009a51b24f3a73c515f to your computer and use it in GitHub Desktop.
Rust code shared from the playground
const _INPUT: &str = "1,2,4";
const INPUT: &str = "63,144,180,149,1,255,167,84,125,65,188,0,2,254,229,24";
const SIZE: usize = 256;
const ROUNDS: usize = 64;
fn main() {
let mut circle: Vec<usize> = (0..SIZE).collect();
let mut pos = 0;
let mut skip_size = 0;
for _ in 0..ROUNDS {
for length in INPUT.bytes().chain(vec![17, 31, 73, 47, 23]) {
let length = length as usize;
for i in 0..length / 2 {
circle.swap((pos + i) % SIZE, (pos + length - 1 - i) % SIZE);
}
pos += length + skip_size;
skip_size += 1;
}
}
let hash: String = circle
.chunks(16)
.map(|block| block.iter().fold(0, |x, &y| x ^ y))
.map(|byte| format!("{:02x}", byte))
.collect();
println!("{}", hash);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment