Created
April 10, 2012 01:17
-
-
Save DavidJRobertson/2347755 to your computer and use it in GitHub Desktop.
XOR tool
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
puts "XOR tool" | |
hexvals = Array.new | |
puts "Enter first value in hex: " | |
hexvals << gets.chomp | |
puts "Enter second value in hex: " | |
hexvals << gets.chomp | |
vals = Array.new | |
hexvals.each do |hexval| | |
vals << [hexval].pack("H*") | |
end | |
val1 = vals[0] | |
val2 = vals[1] | |
puts "Answer: " | |
val1.bytes.each_with_index do |b1, i| | |
b2 = val2.bytes.to_a[i] | |
b2 = b2.nil? ? 0 : b2 | |
answer = b1 ^ b2 | |
ansstring = answer.to_s(16) | |
if ansstring.length == 1 | |
print "0" | |
end | |
print ansstring | |
end | |
print "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment