🐛 Fix decrypt chunk
This commit is contained in:
parent
602b4b12d4
commit
9994dffed2
1 changed files with 6 additions and 5 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue