Created
March 10, 2015 10:53
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
def trim(v) | |
v & 0xffffffff | |
end | |
def scramble(v) | |
v ^= 0x1ca7bc5b | |
v *= 0x1ca7bc5b | |
v = trim(v) | |
v = ((v >> 1) & 0x55555555) | trim((v & 0x55555555) << 1) | |
v = ((v >> 2) & 0x33333333) | trim((v & 0x33333333) << 2) | |
v = ((v >> 4) & 0x0F0F0F0F) | trim((v & 0x0F0F0F0F) << 4) | |
v = ((v >> 8) & 0x00FF00FF) | trim((v & 0x00FF00FF) << 8) | |
v = ( v >> 16 ) | trim( v << 16) | |
v *= 0x6b5f13d3 | |
v = trim(v) | |
v ^= 0x1ca7bc5b | |
end | |
def test | |
0.step(0xffffffff,10000) { |x| | |
raise unless x == scramble(scramble(x)) | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lol comment