Lion Cipher Lab

Predict a Mersenne Twister (MT19937) PRNG from its output — then switch to a CSPRNG and watch the attack die

Why it matters

Almost every language ships a fast general-purpose random number generator, and in most of them it is the Mersenne Twister — Python's random module, Ruby's Random, PHP's mt_rand, NumPy's legacy RandomState. It is genuinely excellent for simulations and games: it is fast and its output passes the hard statistical randomness batteries. And that is exactly the trap, because developers reach for the thing called 'random' to mint security tokens — password-reset links, coupon codes, session ids, API keys, 'unguessable' URLs — and the Mersenne Twister is NOT cryptographically secure. The Python…

What you'll learn

Steps in this lab

  1. PRNG vs CSPRNG: the one distinction this whole lab rests on
  2. Set up, and understand the target: how MT19937 turns state into output
  3. Implement untemper, recover the state, and predict every future token
  4. The often-EASIER break: a weak seed over a time window
  5. The fix: mint tokens with a CSPRNG, then rerun the identical attack
  6. Honest negatives — exactly when the state-recovery attack gets HARD
  7. The judgment: what to actually take away

Open the full interactive lab →