-
-
Save murachue/858348 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/ruby | |
# | |
# Stringクラスにxor(^)を追加してみるテスト。主にCTF用? | |
# | |
class String | |
def ^(str) | |
sho = self | |
lon = str | |
sho, lon = lon, sho if sho.size > lon.size | |
(0...lon.size).inject("") {|r,i| r + (lon[i] ^ sho[i % sho.size]).chr} | |
end | |
def hexdump | |
(0...self.size).inject("") {|r,i| r + ("%02x "%self[i]) } | |
end | |
end | |
a = "\x01\x23\x45\x67\x89\xab\xcd\xef" | |
b = "\x76\x54\x32\x10" | |
c = a ^ b | |
puts c.hexdump # => "\x77\x77\x77\x77\xFF\xFF\xFF\xFF" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment