Skip to content

Mersenne Twister

Robert Jordan edited this page Mar 10, 2020 · 5 revisions

Mersenne Twister

⚠️ WORK IN PROGRESS ⚠️

Mersenne Twister is an extremely common Pseudo-Random number generator used by CatSystem2 for encryption, and in-game graphics randomization. CatSystem2 uses a MT19937 ver.1999/10/29 variant. This specific variant can be identified by the seeding operation, which performs 2 multiplications of 69069 (0x10dcd) on the seed for each value in the state.

Encryption

Mersenne Twister randomization is used for generating 32-bit keys, that see use in other encryption methods, such as: Blowfish ciphers and Beaufort ciphers.

In KIF Archives, Mersenne Twister is seeded and used to generate the "__key__.dat" entry's Offset and then Length fields, which are then seeded into Mersenne Twister again to encrypt file data with a Blowfish cipher.

Used By

Implementation

The implementation of Mersenne Twister used by CatSystem2, is the 1999/10/29 version of MT19937 developed by Makoto Matsumoto and Takuji Nishimura and made publicly available online below. It is very likely that these are the exact source files used in CatSystem2's code. In the assembly, there are multiple implementations of the same Seed functions for Real numbers and Integers, they each have their own static mt state fields, and there's also another Integer static implementation (identical as far as I can tell) inside the assembly.

Clone this wiki locally