Skip to content

Instantly share code, notes, and snippets.

@DavidJRobertson
Created April 10, 2012 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidJRobertson/2347755 to your computer and use it in GitHub Desktop.
Save DavidJRobertson/2347755 to your computer and use it in GitHub Desktop.
XOR tool
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