Created
March 15, 2025 12:58
-
-
Save drewstaylor/33a7b21cccb65c6711b095ec77e5d7da to your computer and use it in GitHub Desktop.
Remembering that time I had to XOR in JavaScript...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const xor = function (a, b) { | |
if (!Buffer.isBuffer(a)) a = new Buffer.from(a); | |
if (!Buffer.isBuffer(b)) b = new Buffer.from(b); | |
let res = [] | |
const len = (a.length > b.length) | |
? b.length | |
: a.length; | |
for (let i = 0; i < len; i++) { | |
res.push(a[i] ^ b[i]); | |
} | |
return new Buffer.from(res); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment