Class: String

Inherits:
Object
  • Object
show all
Includes:
Crypt::Noise
Defined in:
lib/crypt/noise.rb,
lib/crypt/stringxor.rb

Instance Method Summary collapse

Methods included from Crypt::Noise

#add_noise, #remove_noise

Instance Method Details

#^(aString) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/crypt/stringxor.rb', line 3

def ^(aString)
  a = self.b.unpack('C'*(self.length))
  b = aString.b.unpack('C'*(aString.length))
  if (b.length < a.length)
    (a.length - b.length).times { b << 0 }
  end
  xor = "".b()
  0.upto(a.length-1) { |pos|
    x = a[pos] ^ b[pos]
    xor << x.chr()
  }
  return(xor)
end