# Breaking a Mersenne-twister RNG with unsequential outputs

Pardon me for this newbie-ish question. I'm still a novice in cryptography . I have an application that outputs random numbers from 0 - 12 (endpoints inclusive) unsequentially (some outputs are thrown off) using the mersenne twister algorithm and i would like to break and predict its seed in Python but i don't know what to program?

Once again please pardon my little knowledge in this space.

• Are you taking the twister outputs modulo 13? Jun 16, 2020 at 3:51
• Or if you don't know implementation, what method call are you making in python? Jun 17, 2020 at 15:14
• i use random.randint(0, 12) Jun 21, 2020 at 11:49

If you can identify which outputs are revealed and which are thrown off (ex. every other output is thrown off), you may be able to successfully analyze the twister so that you can predict future outputs.

However, the bigger problem here is that you are limiting outputs to the range [0,12]. With a 32 or 64 bit word length, a set of numbers in that range will not reveal nearly enough information about the state (even if none were discarded and all outputs were revealed to you).

• it's not just one number. it's a series of unsequential outputs in range 0 - 12 Jun 16, 2020 at 14:35
• Yes, this answer takes that into account. I will edit the wording so it is more clear. Do you understand the issues at hand? Jun 17, 2020 at 15:12
• I have 1665 of such outputs which is enough. My problem in all this is that i understand the theory (beginner level) but i have no idea what to code Jun 21, 2020 at 11:48
• "With a 32 or 64 bit word length, a set of numbers in that range will not reveal nearly enough information about the state"; that depends on the mapping between the 32 bit outputs and the value [0,12]. If the mapping is $\lfloor n / (2^{32}/13) \rfloor$, that gives you the msbit sometimes, which is quite enough. If it's $n \bmod 13$, well, there's no immediate way to attack that Nov 14, 2020 at 17:10
• Correction: it's not quite enough with only 1665 outputs; rather more would be required... Nov 14, 2020 at 17:19