Module: Crypt::StringXor

Included in:
String
Defined in:
lib/crypt/stringxor.rb

Instance Method Summary collapse

Instance Method Details

#^(a_string) ⇒ Object



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

def ^(a_string)
  a = self.unpack('C'*(self.length))
  b = a_string.unpack('C'*(a_string.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