Home
Writeups Misc About
RSA or RNG

RSA or RNG

I did not manage to solve this. Have to search on Github for some solution (very shameless to admit). I made some mistakes in solving the problem, which will be mentioned below. The challenge is similar to the so easy rsa challenge in HITCON 2021, in which maple3142 has a good blog entry about.

Denote the Linear Congruential Generator (LCG) function as f(x)=ax+b, we have q=fx(p) for some unknown x[2,1000]. The range is from running the LCG for a bit, and due to the distribution of primes.

We also have n=pq, or substituting the above: n=pfx(p). fx(p) is some function of degree 1 in terms of p. Indeed, for instance, f2(p)=a(ap+b)+b=a2p+ab+b, and obviously it is of degree 1. Hence, pfx(p)n is some quadratic equation in terms of p.

I made the mistake of not looking at the problem in this manner, seeing the a2 and a3 makes me think that the polynomial is of very high degree, which is very wrong. Also I did not think of this in the idea of p,q being related to each other, and the fact that the x can be brute forced. These are all new ideas and I am glad I actually looked at the solution to figure this out.

To solve the quadratic in modulo 2512, one can use the Hensel's lemma, or work in 2-adic. Both I have no idea how the math works, but the 2-adic idea looks just like solving normal equations. The following is the Sage implementation of the latter idea:

The Hansel lifting solution (and the one I search on Github) is at this link. Some good resource: Youtube video on how to solve the problem when modulo prime, and blog post about solving quadratic congruences.

For prime modulus, we can also do factoring (which is the same as calculating the roots). See the implementation at this HITCON 2021 writeup