Noob RSA Returns

Cryptography · BITSCTF 2025

Problem

Description

As this challenge only had 13 solves at the end of the CTF, I deliberately chose it and decided to explain the solution.

574B
Open
1KB
Open

Analysis

One thing we need to focus on is the equation that defines K Mathematically expressed as:

K=(Ap2Cp+D)dK = (A\cdot p^{2}-C\cdot p+D)\cdot d

By multiplying both sides, we will get:

Ke=(Ap2Cp+D)deK \cdot e= (A\cdot p^{2}-C\cdot p+D)\cdot d \cdot e

In RSA, ed1modΦ(n)\color{Red} e\cdot d \equiv 1 mod \Phi(n) or ed=1+zΦ(n)\color{Red} e\cdot d =1+z\cdot\Phi(n), where z is some integer.

For example, 111mod511 \equiv1mod5 or 11=1+z511=1+z\cdot5, where z = 2.

Substitute ede \cdot d into the equation above.

Ke=(Ap2Cp+D)(1+zΦ(n))K \cdot e= (A\cdot p^{2}-C\cdot p+D) \cdot (1+z\Phi(n))
K(Ap2Cp+D)=(1+zΦ(n))e \frac{K}{(A\cdot p^{2}-C\cdot p+D)} = \frac{(1+z\Phi(n))}{e}

Solution

Brute-forcing z until we get an integer value for p.

  • Finding p:

    • The script tries to find the prime factor ppp by solving an equation for each value of z in the range [START, e]

    • The equation relates p, z, and other parameters (including n) to eventually factor nnn.

  • Equation Setup:

    • The equation:

      is derived to calculate ppp. It depends on the unknown prime p, and the loop iterates over possible values of z.

  • Loop and Progress Bar:

    • The tqdm loop iterates over values of z, solving the equation to find valid integer solutions for p. Once a valid p is found, it exits the loop.

Since the correct value of z was 42677, I set the starting value to 42675. Setting larger values, but still less than e, is suitable for capturing z as it saves both time and memory.

Flag: BITSCTF{I_H0P3_Y0UR3_H4V1NG_FUN_S0_F4R_EHEHEHEHEHO_93A5B675}

Last updated