Created
March 7, 2011 10:11
-
-
Save yoggy/858330 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) | |
raise "Illigal size!" if self.size != str.size | |
(0...self.size).inject("") {|r,i| r += (self[i] ^ str[i]).chr} | |
end | |
def hexdump | |
(0...self.size).inject("") {|r,i| r += ("%02x "%self[i])} | |
end | |
end | |
a = "\x01\x23\x45\x67" | |
b = "\x76\x54\x32\x10" | |
c = a ^ b | |
puts c.hexdump # => "\x77\x77\x77\x77" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
injectの使い方間違えてるので https://gist.github.com/858352 の方を参照してくださいw