Xor strings in ruby

I have a line, say, "123 | ABC | test | 12345 | FF", and I want the xor ascii value of each character and print the result in hexadecimal format.

What is the easiest way?

+1
source share
2 answers

In Ruby 1.8.7 or 1.9.1:

input.bytes.inject { |a,b| a ^ b }.to_s(16) 
+4
source

Found...

 lrc = 0 input.each_byte do | c | lrc ^= c end hexVal = lrc.to_s(16) 
+3
source

All Articles