Toggle light/dark

LCG Cracker

JavaNumber TheoryCryptanalysis
repo ↗ demo ↗

A Java class that recovers the hidden parameters (a, b, m) of any linear congruential generator from a handful of outputs — and predicts its next number.

image by xkcd, comic 221

A companion build to my post on why LCGs aren’t really random.

Given five or more consecutive outputs of a linear congruential generator, the cracker reconstructs the modulus via a gcd of differenced terms, recovers the multiplier with a modular inverse, solves for the addend, and predicts the next value — all in polynomial time.

int[] outputs = {3, 2, 8, 4, 1, 5};
lcgCracker c = new lcgCracker(outputs);
c.runCracker();

See the post for the full derivation and the math behind each step.