Skip to content

Instantly share code, notes, and snippets.

@wjessop
Created December 2, 2013 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wjessop/7752495 to your computer and use it in GitHub Desktop.
Save wjessop/7752495 to your computer and use it in GitHub Desktop.
class Array
def xor(key)
a = dup
a.length.times { |n| a[n] ^= key[n % key.size] }
a
end
end
stra = "123abc"
strb = "123adc"
stra.codepoints.to_a.xor(strb.codepoints.to_a)
=> [0, 0, 0, 0, 6, 0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment