Skip to main content
Challenges LCG: recovering the seed
Cryptography Medium LCG Solves: 7

LCG: recovering the seed

Author: CyberSamSU
Points
35

LCG (Linear Congruential Generator) is the oldest and simplest PRNG: x[i+1] = (a * x[i] + c) mod m. Three parameters — the multiplier a, the increment c, and the modulus m.

The main vulnerability of an LCG is that it works in both directions. If we solve the formula for x[i]: x[i] = a^(-1) * (x[i+1] - c) mod m. Here a^(-1) is the modular inverse of a modulo m. That is, if we know one internal state, we can step the generator backward as much as we want and find the starting seed.

The program encrypted the flag like this:

m = 2**32
a = 1664525
c = 1013904223

def keyingi(x):
    return (a * x + c) % m

x = urug                       # x_0 — maxfiy urug'
kalit = []
for i in range(44):
    x = keyingi(x)             # x_1, x_2, x_3, ...
    kalit.append((x >> 24) & 0xFF)      # holatning eng yuqori bayti

ct = bytes(b ^ k for b, k in zip(bayroq, kalit))
# ... dastur yana ishlashda davom etdi ...

The debugger showed the internal state when the program had completed the 50th step:

x_50 = 3116764485

Encrypted flag (hex):

2010916f31615abce1b6b5ab5ab2a1955f4e53e8de70a38adb93de20b6d5e785
bc3f9729698d79589fcaf9cc

Modular inverse in Python: pow(a, -1, m) (Python 3.8+). Since a is odd, the modular inverse modulo 2^32 certainly exists.

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

First solvers

1. Лазиз 04.10.2026
2. Mirjaxon Qaxxarov 27.10.2026
3. Odam 05.11.2026
4. arcanum 11.11.2026
5. Jasmin Xuseinova 15.11.2026
6. Aminova 18.11.2026
7. hacker_777 19.11.2026