Skip to main content
Challenges MT19937: reverse tempering
Cryptography Hard Mersenne Twister Solves: 10

MT19937: reverse tempering

Author: CyberSamSU
Points
75

Mersenne Twister (MT19937) is the generator behind the random module in Python, PHP, Ruby and many other languages. Its internal state consists of 624 32-bit words. Before each output, the state word is passed through a mixing function called tempering — this improves the statistical quality of the numbers.

Important point: tempering is not encryption. It has no secret key, only shift and XOR operations. And each operation is reversible. Thus, it is possible to exactly recover the internal state word from the output number. This is the first and most important step in cracking MT19937.

def temper(x):                  # x — MT19937 ning ichki holat soʻzi
    y = x
    y ^= y >> 11
    y ^= (y << 7)  & 0x9D2C5680
    y &= 0xFFFFFFFF
    y ^= (y << 15) & 0xEFC60000
    y &= 0xFFFFFFFF
    y ^= y >> 18
    return y & 0xFFFFFFFF       # aynan shu son chiqishga beriladi

To derive the reverse operations, it is enough to understand two patterns:

  • y = x ^ (x >> s) — here the highest s bits of y are the same as those of x. Knowing them, we find the next s bits and thus go down.
  • y = x ^ ((x << s) & mask) — exactly the same, but we go up starting from the lowest s bits.
  • Practical trick: if you repeat x = y; x = y ^ (x >> s) several times, the result stabilizes and becomes exactly the original x.

The generator output three consecutive numbers:

y1 = 112016232
y2 = 3673192664
y3 = 3008816174

Find their corresponding internal state words (that is, find such x that temper(x) = y) and assemble the flag: BAYROQ{PRNG_untemper_<x1>_<x2>_<x3>} — the numbers are in decimal format.

Enumerating all 2^32 variants (brute-force) will not work here — write the inverse function.

Hints 3
Opening a hint reduces the points you get for solving this challenge.
Hint 1 −7 pts Log in
Hint 2 −15 pts Log in
Hint 3 −22 pts Log in
To submit a flag, log in.

First solvers

1. Абдул 08.09.2026
2. W.o.X 17.09.2026
3. Лазиз 04.10.2026
4. BlackCipher 08.10.2026
5. testrejim 09.10.2026
6. Mirjaxon Qaxxarov 27.10.2026
7. Odam 04.11.2026
8. arcanum 11.11.2026
9. pentester_uz 12.11.2026
10. Jasmin Xuseinova 15.11.2026