class String

Public Instance Methods

xor(other) click to toggle source
# File lib/hsmr.rb, line 251
def xor(other)
  if other.empty?
    self
  else
    a1        = self.unpack("a2"*(self.length/2)).map {|x| x.hex }
    a2        = other.unpack("a2"*(other.length/2)).map {|x| x.hex }
    #a2 *= 2   while a2.length < a1.length

    #a1.zip(a2).collect{|c1,c2| c1^c2}.pack("C*")
    a1.zip(a2).
    map {|x,y| x^y}.
    map {|z| z.to_s(16) }.
    map {|c| c.length == 1 ? '0'+c : c }.
    join.upcase      
  end
end