Skip to main content
Challenges MT19937: 624 outputs and the future
Cryptography Expert Mersenne Twister Solves: 9

MT19937: 624 outputs and the future

Author: CyberSamSU
Points
170

The internal state of MT19937 is 624 32-bit words. The generator takes these words one by one, passes them through the temper() function, and outputs the result. When the 624 words run out, the "twist" operation updates the entire array and the cycle starts again.

There is a fatal vulnerability here: temper() is invertible. So an attacker who has seen 624 consecutive outputs reverses each using untemper() and collects a complete copy of the internal array. After that, they calculate the entire future (and past) of the generator. No brute-force is needed — this is an exact calculation.

This is exactly why generating a key, token or password with the random module is strictly forbidden.

Server code:

import random

random.seed(<maxfiy urugʻ>)

# 1) jurnalga (log) 624 ta chiqish yozildi
chiqishlar = [random.getrandbits(32) for _ in range(624)]

# 2) shundan keyingi chiqishlar kalit sifatida ishlatildi
soz = [random.getrandbits(32) for _ in range(10)]
kalit = b''.join(w.to_bytes(4, 'big') for w in soz)
ct = bytes(p ^ k for p, k in zip(bayroq, kalit))   # bayroq 39 bayt

The attached chiqishlar.txt file contains those 624 outputs (one decimal number per line, order preserved).

Encrypted flag (hex):

cd0d3b3045adffc2a55cdfc70cda1dbf7741b914942b478db23a09ab1204ab72
eabfa4988927f8

Solution path

  1. Take the untemper() function from the previous challenge.
  2. Untemper each of the 624 outputs — the result is the mt[0..623] array.
  3. Resume the generator from this state. The easiest way is Python's own module: random.setstate((3, tuple(mt) + (624,), None)). Here 624 is the index: on the next request an automatic "twist" will be performed, just like in the real generator.
  4. Now call getrandbits(32) to get the key words, convert them to 4 big-endian bytes, and XOR them with the ciphertext.

If you wish, you can also write MT19937 manually: the twist operation is mt[i] = mt[(i+397)%624] ^ (y >> 1) ^ (0x9908B0DF if y & 1 else 0), where y = (mt[i] & 0x80000000) | (mt[(i+1)%624] & 0x7FFFFFFF).

Attached files
chiqishlar.txt Log in to download
SHA-256 checksums
chiqishlar.txt: 31b5a1ac92c1bdd55dff2cf9442a698ba8814917f8ab00f956b228aac876394a
Hints 3
Opening a hint reduces the points you get for solving this challenge.
Hint 1 −17 pts Log in
Hint 2 −34 pts Log in
Hint 3 −51 pts Log in
To submit a flag, log in.

First solvers

1. W.o.X 09.09.2026
2. Stiv_084100 11.09.2026
3. Лазиз 01.10.2026
4. 11111tttt 09.10.2026
5. testrejim 09.10.2026
6. Raumdeuter 09.10.2026
7. Mirjaxon Qaxxarov 26.10.2026
8. Odam 04.11.2026
9. pentester_uz 12.11.2026