Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
文字列があり、「123 | ABC | test | 12345 | FF」と言って、各文字のASCII値をxorし、結果を16進数で出力したいとします。
最も簡単な方法は何ですか?
それを見つけた...
lrc = 0 input.each_byte do | c | lrc ^= c end hexVal = lrc.to_s(16)
Ruby 1.8.7 または 1.9.1 の場合:
input.bytes.inject { |a,b| a ^ b }.to_s(16)