Xor of string in ruby

前端 未结 2 1176
礼貌的吻别
礼貌的吻别 2020-12-07 04:55

I have a string, lets say \"123|ABC|test|12345|FF\" and I want to xor the ascii value of each character and print the result in hex.

What is the simplest way?

2条回答
  •  天涯浪人
    2020-12-07 05:12

    Found it...

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

提交回复
热议问题