In theory you can xor two whole numbers of any size. Since there is a natural, one-to-one mapping between whole numbers and buffers, it makes sense that the xor operation can and should be preserved across the mapping. That means that, when applied to Buffers, it should treat the shorter array as if it was padded with 0s to the longer array's length, instead of ignoring the longer array's extra data. This is the implementation on current master:
module.exports = function xor (a, b) {
var length = Math.min(a.length, b.length)
var buffer = new Buffer(length)
for (var i = 0; i < length; ++i) {
buffer[i] = a[i] ^ b[i]
}
return buffer
}
It should look more like:
module.exports = function xor (a, b) {
var length = Math.max(a.length, b.length)
var buffer = new Buffer(length)
for (var i = 0; i < length; ++i) {
buffer[i] = (a[i] || 0) ^ (b[i] || 0) // unoptimized, mathematically sound xor
}
return buffer
}
Hope that's clear. Let me know if that doesn't make sense. Thanks!
In theory you can xor two whole numbers of any size. Since there is a natural, one-to-one mapping between whole numbers and buffers, it makes sense that the xor operation can and should be preserved across the mapping. That means that, when applied to
Buffers, it should treat the shorter array as if it was padded with0s to the longer array's length, instead of ignoring the longer array's extra data. This is the implementation on current master:It should look more like:
Hope that's clear. Let me know if that doesn't make sense. Thanks!