From 9994dffed2a4d7e3bc293c67b277fafe37290d56 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Thu, 5 Jul 2018 18:22:20 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20decrypt=20chunk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ssn/decryption/decryptChunk.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ssn/decryption/decryptChunk.ts b/src/ssn/decryption/decryptChunk.ts index 3370756..f98ceee 100644 --- a/src/ssn/decryption/decryptChunk.ts +++ b/src/ssn/decryption/decryptChunk.ts @@ -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;