diff --git a/src/ssn/decryption/modifyPassword.ts b/src/ssn/decryption/modifyPassword.ts index a5417d6..0687018 100644 --- a/src/ssn/decryption/modifyPassword.ts +++ b/src/ssn/decryption/modifyPassword.ts @@ -1,11 +1,11 @@ /** Takes a password as it is included in the extra field, and returns a password that can be used to decode the file. */ -export default function modifyPassword(passwordIn: Uint8Array) { +export default function modifyPassword(passwordIn: Uint8Array): Uint8Array { const passwordLength = passwordIn.byteLength; const passwordOut = new Uint8Array(passwordLength); for (let i = 0; i < passwordLength; i += 1) { if (passwordIn[i] === 0) { break; } - let curChar = passwordIn[i] + ((1 << (i % 32)) & 0xFF); + let curChar = (passwordIn[i] + ((1 << (i % 32)) & 0xFF)) & 0xFF; if (curChar > 0x7E) { if (curChar === 0xFF || curChar === 0x7F) { curChar = 0x3F; @@ -14,7 +14,7 @@ export default function modifyPassword(passwordIn: Uint8Array) { } } if (curChar < 0x21) { - curChar = (curChar | (1 << ((curChar % 3) + 5))) + 1; + curChar = ((curChar | (1 << ((curChar % 3) + 5))) + 1) & 0xFF; } passwordOut[i] = curChar; }