Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/rubius/string.rb

Instance Method Summary collapse

Instance Method Details

#xor(s2) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/rubius/string.rb', line 2

def xor(s2)
  if s2.empty?
    self
  else
    a1 = self.unpack("c*")
    a2 = s2.unpack("c*")
    
    a2 *= 2 while a2.length < a1.length
    
    a1.zip(a2).collect{|c1,c2| c1^c2}.pack("c*")
  end
end