Last active
June 8, 2018 16:02
-
-
Save th0rex/e7b4919c574029f30a81d3b6c2d7a95f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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