Created
May 2, 2011 22:47
-
-
Save hh/952518 to your computer and use it in GitHub Desktop.
My fiddling with http://www.telogis.co.nz/quiz.php
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
z = 3 * 0x41662d2d * 123750872726249 | |
o = [] | |
puts z.to_s(16) | |
while z != 0 | |
# let's eat through z one byte at a time | |
l = z >>4 &0xf #shift right then AND with 16 to get the character | |
r = z &0xf #just AND with 16 to get the XORed with l position in the array | |
o[r^l]=(l + 97).chr #put the character in the correct spot in the array | |
z = z >> 8 #start working on the next 8 bits | |
end | |
word = o.join | |
puts word | |
# might be fun to generate the number from the word... lets create y! | |
y = 0 | |
injection_order = [3,6,8,5,0,9,4,7,1,2] # try to get same number above | |
#injection_order=(0..word.length).to_a.shuffle # get random order | |
injection_order.each do |index| | |
l = word[index] - 97 | |
r = index^l | |
y = y << 4 unless y == 0 | |
y += l | |
y = y << 4 | |
y += r | |
end | |
puts y.to_s(16) | |
raise unless y == z # no error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Copy and paste your code to http://tryruby.org and it is giving error as below. Do I need to test it on a "real" Ruby install?
=> #<NoMethodError: undefined method `-' for "f":String>
Just really curious what the page looks like