Skip to content

Instantly share code, notes, and snippets.

@yoggy
Created March 7, 2011 10:11
Show Gist options
  • Save yoggy/858330 to your computer and use it in GitHub Desktop.
Save yoggy/858330 to your computer and use it in GitHub Desktop.
#!/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"
@yoggy
Copy link
Author

yoggy commented Mar 7, 2011

injectの使い方間違えてるので https://gist.github.com/858352 の方を参照してくださいw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment