five-bells-condition
Version:
Implementation of crypto-conditions in JavaScript
18 lines (15 loc) • 380 B
JavaScript
function xor (a, b) {
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
throw new Error('Arguments must be buffers')
}
if (a.length !== b.length) {
throw new Error('Buffers must be the same length')
}
const result = new Buffer(a.length)
for (let i = 0; i < a.length; i++) {
result[i] = a[i] ^ b[i]
}
return result
}
module.exports = xor