Sha256: 49aa15580df5f32fdaf898b10427cad88797d6428d2387665c310db29e4e7238

Contents?: true

Size: 410 Bytes

Versions: 8

Compression:

Stored size: 410 Bytes

Contents

class String

  # XOR two string.
  #
  # TODO: This is used by crypt.rb, it needs to be documented.

  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

8 entries across 8 versions & 2 rubygems

Version Path
facets-2.4.0 lib/facets/string/xor.rb
facets-2.4.1 lib/facets/string/xor.rb
facets-2.4.4 lib/core/facets/string/xor.rb
facets-2.4.2 lib/core/facets/string/xor.rb
facets-2.4.3 lib/core/facets/string/xor.rb
facets-2.5.0 lib/core/facets/string/xor.rb
facets-2.4.5 lib/core/facets/string/xor.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/core/facets/string/xor.rb