Module: Rubymisc::String
- Defined in:
- lib/rubymisc/ext/string.rb
Instance Method Summary collapse
- #^(key) ⇒ Object (also: #xor)
Instance Method Details
#^(key) ⇒ Object Also known as: xor
5 6 7 8 9 |
# File 'lib/rubymisc/ext/string.rb', line 5 def ^(key) key_bytes = key.bytes.cycle xor_proc = ->(byte) { byte ^ key_bytes.next } bytes.map(&xor_proc).pack('C*').force_encoding(self.encoding) end |