Created
January 8, 2012 03:39
-
-
Save mthelander/1577076 to your computer and use it in GitHub Desktop.
string xor cipher
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 String | |
def xor(key) | |
''.tap do |result| | |
self.size.times do |n| | |
result << (self[n].ord ^ key[n % key.size].ord).chr | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment