im lagging
crypto · LIT 2025 · hihitherethere
Problem
bro im lagging IM LAGGING bro this game sucks
Connect at nc litctf.org 31784
Analysis
This script creates a challenge based on two types of pseudo-random number generators:
LCG (Linear Congruential Generator)
LFG (Lagged Fibonacci Generator)
It generates a sequence of numbers using these, gives you part of the sequence, and then asks you to predict the next number
If you guess correctly, you get the "flag" (like in a CTF challenge).
Step by step
LCG generation (
lcg_generate
)
Uses the formula:
Needs a seed (starting number), multiplier
a
, incrementc
, and modulusm
.Produces a sequence of
total
numbers.
LFG generation (
lfg_from_lcg
)
Starts with the LCG numbers.
Then, for each new number, it sums certain previous outputs (chosen by "lags") and takes it modulo
m
.This makes it harder to predict than plain LCG.
Formula looks like:
Challenge creation (
generate_challenge
)
Picks random lags (positions to look back from).
Picks random
seed
,a
,c
, andm
.Generates an LCG sequence, then turns it into an LFG sequence.
Returns:
A list of recent LFG outputs (
lfg_outputs
)The next LFG output (
next_lfg_output
), which is the "secret answer".
Main program flow
Waits for you to press Enter.
Prints the LFG outputs (the sequence).
Asks you to guess the next number.
If your guess is correct → prints
"Correct"
and shows the contents offlag.txt
.Otherwise → prints
"Wrong"
.
🔎 The Vulnerability
The challenge uses an LFG (Lagged Fibonacci Generator) built on top of an LCG (Linear Congruential Generator).
You get 10,000 outputs and must predict the next one.
Normally hard, but the modulus is composite.
By factoring it into two primes (using FactorDB), we can apply the Chinese Remainder Theorem (CRT) to work modulo smaller primes and recover the hidden parameters.
🔧 How the Exploit Works
Recover
a
andc
:Look at differences between outputs.
Solve equations mod PRIME1 and PRIME2, then recombine with CRT.
Rewind the LCG:
Once
a
andc
are known, back-calculate the internal LCG states.
Find the 50 lags:
Compare expected vs real differences to detect which past positions (lags) are used.
Predict next output:
With LCG states + lags, compute the next LFG number exactly.
📜 Script Flow
Connects to the server.
Reads 10,000 outputs.
Runs the recovery steps above.
Sends the predicted number.
If correct → prints the flag 🎉
✅ In short, the challenge looks unbreakable at first, but by exploiting the composite modulus and carefully reversing the generator’s internals, we can fully recover its state and predict the future output.
Thank you 👏
Last updated