Created
May 28, 2015 20:58
-
-
Save dmb2/c413d6ba437c8e1364ee to your computer and use it in GitHub Desktop.
Xor two strings, assumes you've got a Converters class that converts the bytestring to hex first.
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
class CryptoTools | |
def self.xor_str(str_a,str_b) | |
if str_a.length != str_b.length | |
raise "Length of input strings doesn't match!" | |
end | |
str_a.bytes.zip(str_b.bytes).map{ |x,y| x^y }.pack("C*") | |
end | |
def self.hex_xor(hex_a,hex_b) | |
Converters.str_to_hex(xor_str(Converters.hex_to_bytes(hex_a), | |
Converters.hex_to_bytes(hex_b))) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment