Sha256: ebfbbaf4e0dfefd8d0ac95534cbc3be9843e64dc574e3bc0c50e6754a3db0e7f

Contents?: true

Size: 526 Bytes

Versions: 9

Compression:

Stored size: 526 Bytes

Contents

class String

  # Binary XOR of two strings. 
  #
  #   puts "\000\000\001\001" ^ "\000\001\000\001"
  #   puts  "\003\003\003" ^ "\000\001\002"
  #
  # _produces_
  #
  #   "\000\001\001\000"
  #   "\003\002\001"
  #
  def ^(aString)
    a = self.unpack('C'*(self.length))
    b = aString.unpack('C'*(aString.length))
    if (b.length < a.length)
      (a.length - b.length).times { b << 0 }
    end
    xor = ""
    0.upto(a.length-1) { |pos|
      x = a[pos] ^ b[pos]
      xor << x.chr()
    }
    return(xor)
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
facets-2.8.4 lib/core/facets/string/xor.rb
facets-2.8.3 lib/core/facets/string/xor.rb
facets-2.8.2 lib/core/facets/string/xor.rb
facets-2.8.1 lib/core/facets/string/xor.rb
facets-2.8.0 lib/core/facets/string/xor.rb
facets-2.7.0 lib/core/facets/string/xor.rb
facets-2.6.0 lib/core/facets/string/xor.rb
facets-2.5.1 lib/core/facets/string/xor.rb
facets-2.5.2 lib/core/facets/string/xor.rb