Sha256: 610caf648cc8d0687815c2b41c918b5c831cf9738d551b035a8bf8ba1329a916

Contents?: true

Size: 518 Bytes

Versions: 10

Compression:

Stored size: 518 Bytes

Contents

class String

  # Binary XOR of two strings. 
  #
  #   a = "\000\000\001\001" ^ "\000\001\000\001"
  #   b = "\003\003\003" ^ "\000\001\002"
  #
  #   a  #=> "\000\001\001\000"
  #   b  #=> "\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

10 entries across 9 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/string/xor.rb
facets-3.1.0 lib/core/facets/string/xor.rb
facets-3.0.0 lib/core/facets/string/xor.rb
facets-2.9.3 lib/core/facets/string/xor.rb
facets-2.9.2 src/core/facets/string/xor.rb
facets-2.9.2 lib/core/facets/string/xor.rb
facets-2.9.1 lib/core/facets/string/xor.rb
facets-2.9.0 lib/core/facets/string/xor.rb
facets-2.9.0.pre.2 lib/core/facets/string/xor.rb
facets-2.9.0.pre.1 lib/core/facets/string/xor.rb