Skip to content

Instantly share code, notes, and snippets.

@yakovenkodenis
Created November 21, 2022 13:58
Show Gist options
  • Save yakovenkodenis/7e310701788cfd9e7e418960a084a504 to your computer and use it in GitHub Desktop.
Save yakovenkodenis/7e310701788cfd9e7e418960a084a504 to your computer and use it in GitHub Desktop.
_unmask(payload, maskingKey) {
const result = Buffer.alloc(payload.byteLength);
for (let i = 0; i < payload.byteLength; ++i) {
const j = i % 4;
const maskingKeyByteShift = j === 3 ? 0 : (3 - j) << 3;
const maskingKeyByte = (maskingKeyByteShift === 0 ? maskingKey : maskingKey >>> maskingKeyByteShift) & 0b11111111;
const transformedByte = maskingKeyByte ^ payload.readUInt8(i);
result.writeUInt8(transformedByte, i);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment