Revert "Rework XOR code to make more sense"

This reverts commit 699a8e91d2.
bug/bundler_fix
Brent Cook 2016-11-18 07:52:08 -06:00
parent 005d34991b
commit 16b5f40dae
2 changed files with 8 additions and 9 deletions

View File

@ -673,12 +673,11 @@ class Packet < GroupTlv
#
def to_r
raw = super
xor_key = ''
xor_key << (rand(254) + 1).chr
xor_key << (rand(254) + 1).chr
xor_key << (rand(254) + 1).chr
xor_key << (rand(254) + 1).chr
result = xor_key + xor_bytes(xor_key, raw)
xor_key = rand(254) + 1
xor_key |= (rand(254) + 1) << 8
xor_key |= (rand(254) + 1) << 16
xor_key |= (rand(254) + 1) << 24
result = [xor_key].pack('N') + xor_bytes(xor_key, raw)
result
end
@ -689,7 +688,7 @@ class Packet < GroupTlv
# the TLV values.
#
def from_r(bytes)
xor_key = bytes[0,4]
xor_key = bytes[0,4].unpack('N')[0]
super(xor_bytes(xor_key, bytes[4, bytes.length]))
end
@ -698,7 +697,7 @@ class Packet < GroupTlv
#
def xor_bytes(xor_key, bytes)
result = ''
bytes.bytes.zip(xor_key.bytes.cycle).each do |b|
bytes.bytes.zip([xor_key].pack('V').bytes.cycle).each do |b|
result << (b[0].ord ^ b[1].ord).chr
end
result

View File

@ -57,7 +57,7 @@ class PacketParser
# payload length left to the number of bytes
# specified in the length
if (self.hdr_length_left == 0)
xor_key = raw[0, 4]
xor_key = raw[0, 4].unpack('N')[0]
length_bytes = packet.xor_bytes(xor_key, raw[4, 4])
# header size doesn't include the xor key, which is always tacked on the front
self.payload_length_left = length_bytes.unpack("N")[0] - (HEADER_SIZE - 4)