This problem is the problem I did not manage to solve in NUS Greyhats GreyCTF2022. Although I am pretty close to the solution, there is one trick that I missed that is crucial to this particular type of challenge.
xxxxxxxxxx
N = p * q
c1 = (2 * p + 3 * q) ** e1 mod N
c2 = (5 * p + 7 * q) ** e2 mod N
We are given the above system of equations, and the goal is to solve for
This result is derived from the fact that the expansion of
The task is to solve this system of equations. The aim is to eliminate one of the variables, in this case I choose
From the above result from Newton's binomial expansion, the system of equations now become:
We want to eliminate
Subtracting the two equations, we have
Clearly,
From
xxxxxxxxxx
N = <N given>
e1 = <e1 given>
e2 = <e2 given>
c1 = <c1 given>
c2 = <c2 given>
lhs1 = pow(c1, e2, N)
lhs2 = pow(c2, e1, N)
rhs_f1 = pow(5, e1 * e2, N)
rhs_f2 = pow(2, e1 * e2, N)
D = (lhs1 * rhs_f1 - lhs2 * rhs_f2) % N
q = math.gcd(D, N)
p = N // q
print('crypto{' + p + ', ' + q + '}')