Skip to content

Instantly share code, notes, and snippets.

@th0rex
Last active June 8, 2018 16:02
Show Gist options
  • Save th0rex/e7b4919c574029f30a81d3b6c2d7a95f to your computer and use it in GitHub Desktop.
Save th0rex/e7b4919c574029f30a81d3b6c2d7a95f to your computer and use it in GitHub Desktop.
fn parity(xs: &[u8]) -> u64 {
let mut ret = 0u64;
for (i, _) in xs.iter().enumerate() {
let mut acc = 0;
for j in i..i + 8 {
let x = xs[j % xs.len()];
acc ^= (x >> (7 - ((i + 1) % 8))) & 0b1;
}
ret |= (acc as u64) << (xs.len() - (i+1));
}
ret
}
fn main() {
println!(
"0x{:X}",
parity(&"CRYPT0GR4PHY".bytes().collect::<Vec<_>>())
);
println!(
"0x{:X}",
parity(&"BSYPT0GR4PHY".bytes().collect::<Vec<_>>())
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment