web/src/decrypt/qmc_key.test.ts

27 lines
779 B
TypeScript
Raw Normal View History

2021-12-18 13:55:31 +00:00
import { QmcDeriveKey, simpleMakeKey } from '@/decrypt/qmc_key';
import fs from 'fs';
2021-12-16 17:28:48 +00:00
2021-12-18 13:55:31 +00:00
test('key dec: make simple key', () => {
expect(simpleMakeKey(106, 8)).toStrictEqual([0x69, 0x56, 0x46, 0x38, 0x2b, 0x20, 0x15, 0x0b]);
});
2021-12-16 17:28:48 +00:00
function loadTestDataKeyDecrypt(name: string): {
2021-12-18 13:55:31 +00:00
cipherText: Uint8Array;
clearText: Uint8Array;
2021-12-16 17:28:48 +00:00
} {
return {
cipherText: fs.readFileSync(`testdata/${name}_key_raw.bin`),
2021-12-18 13:55:31 +00:00
clearText: fs.readFileSync(`testdata/${name}_key.bin`),
};
2021-12-16 17:28:48 +00:00
}
2021-12-18 13:55:31 +00:00
test('key dec: real file', async () => {
const cases = ['mflac_map', 'mgg_map', 'mflac0_rc4', 'mflac_rc4'];
2021-12-16 17:28:48 +00:00
for (const name of cases) {
2021-12-18 13:55:31 +00:00
const { clearText, cipherText } = loadTestDataKeyDecrypt(name);
const buf = QmcDeriveKey(cipherText);
2021-12-16 17:28:48 +00:00
2021-12-18 13:55:31 +00:00
expect(buf).toStrictEqual(clearText);
2021-12-16 17:28:48 +00:00
}
2021-12-18 13:55:31 +00:00
});