Cyberleague 2025

Baby LCG

Crypto | Pre-CTF

I just started learning about LCG!

Unfortunately, it seems that LCG is quite weak, given how there are so many papers showing how easily you can crack LCG parameters.

Findings from the given source file:

  • An AES-CBC encrypted ciphertext with its IV

  • The modulus and three terms (19th, 38th, and 57th) from a Linear Congruential Generator (LCG)

  • The 1st term of the LCG serves as the AES encryption key

The solution approach is to reverse the given LCG numbers to get the initial term for the decryption key. Here is a good read on LCG Attack : https://msm.lt/posts/cracking-rngs-lcgs/

The LCG generator is defined by the recurrence relation:

Xn+1=aXn+cβ€…modβ€…pX_{n+1} = aX_n + c \: mod \: p

What makes this challenge unique is that instead of consecutive terms, we're given values at fixed intervals of 19. However, this property can still be exploited to recover the initial seed.

For any LCG sequence, we can express terms with fixed intervals using the same coefficient structure. Consider the following relations:

X6=a2X4+cβ‹…a2βˆ’1aβˆ’1mod  pX_6 = a^2 X_4 + c \cdot \frac{a^2 - 1}{a - 1} \mod p
X4=a2X2+cβ‹…a2βˆ’1aβˆ’1mod  pX_4 = a^2 X_2 + c \cdot \frac{a^2 - 1}{a - 1} \mod p

Notice that despite the gaps between terms, the coefficient patterns remain consistent at equal intervals. We can apply this principle to our given terms X19X_{19}, X38X_{38} and X57X_{57} to determine the coefficients needed to calculate the initial term X0X_0.

Here is the solution script:

└─$ CYBERLEAGUE{LCG_W1th_N0n-C0n53cu71v3_0u7pu7_15_57111_W34k!}

Last updated