🐛 Fix decrypt chunk

This commit is contained in:
C-3PO 2018-07-05 18:22:20 +02:00
parent 602b4b12d4
commit 9994dffed2
Signed by: c3po
GPG key ID: 62993C4BB4D86F24

View file

@ -19,11 +19,12 @@ import updateKeys from './lib/updateKeys';
return { decryptedChunk, keys: [key0, key1, key2] };
}*/
export default function getDecryptor([key0, key1, key2]: [number, number, number]) {
export default function getDecryptor(decryptionKeys: [number, number, number]) {
let [key0, key1, key2] = decryptionKeys;
let position = 0;
return (encryptedChunk: Buffer) => {
const decryptedChunk = Buffer.alloc(encryptedChunk.length);
const decryptedChunk = Buffer.alloc(encryptedChunk.length - Math.max(12 - position, 0));
for (let i = 0; i < encryptedChunk.length; i += 1) {
//read byte
@ -34,6 +35,9 @@ export default function getDecryptor([key0, key1, key2]: [number, number, number
const decryptedByte = (keyPart * (keyPart ^ 1)) >>> 8;
curChar ^= decryptedByte & 0xFF;
//update keys
[key0, key1, key2] = updateKeys([key0, key1, key2], curChar);
//write byte
if (position + i < 12) {
//do nothing
@ -42,9 +46,6 @@ export default function getDecryptor([key0, key1, key2]: [number, number, number
} else {
decryptedChunk.writeUInt8(curChar, i);
}
//update keys
[key0, key1, key2] = updateKeys([key0, key1, key2], curChar);
}
position += encryptedChunk.length;