Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/hsmr.rb
Instance Method Summary collapse
Instance Method Details
#xor(other) ⇒ Object
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# 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 |