Module: Krypt::Helper::XOR

Included in:
Krypt::HMAC, PBKDF2
Defined in:
lib/krypt_missing.rb

Instance Method Summary collapse

Instance Method Details

#xor(s1, s2) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/krypt_missing.rb', line 14

def xor(s1, s2)
  String.new.tap do |result|
    s1.bytes.each_with_index do |b, i|
      result << (b ^ s2.getbyte(i))
    end
  end
end

#xor!(recv, other) ⇒ Object



22
23
24
25
26
27
# File 'lib/krypt_missing.rb', line 22

def xor!(recv, other)
  recv.bytes.each_with_index do |b, i|
    recv.setbyte(i, b ^ other.getbyte(i))
  end
  recv
end