RRSA Primes of the form x*r + 1

crypto
flag SkillBit{aLLLways_th3_w4yy}

1. The source

rrsa.zip ships chal.py plus one line of published output:

python
1from secret import *
2r = 1333932344710022001826837667329537548527   # known, given
3
4p = x * r + 1
5q = y * r + 1
6n = p*q
7
8flag = b'SkillBit{REDACTED}'.hex()
9flag = int(flag, 16)
10ct = pow(flag, 65537, n)
11print(f'{ct=}')
12print(f'{n=}')

So both primes are of the form (something)*r + 1 - i.e. r divides p-1 and q-1. "Putting the R in RRSA."

2. The observation - recover x+y for free

Expand n:

output
n = (xr+1)(yr+1) = x*y*r^2 + (x+y)*r + 1

Therefore

output
n - 1 = r * ( x*y*r + x + y )

Let A = (n-1)/r. Then A = x*y*r + (x+y), and taken mod r:

output
A % r == (x + y) % r

The primes sit near sqrt(n) ~ 3e57, while r ~ 1.3e39, so x, y ~ 2.2e18 and x + y < r. That means (x + y) % r is x + y exactly - no wrap. So:

  • s = A % r -> s = x + y
  • xy = (A - s) / r -> xy = x*y

x and y are the roots of z^2 - s*z + xy = 0, whose discriminant is the perfect square (x-y)^2. Recover them, rebuild p, q, and decrypt.

3. Solve

python
1import math
2
3ct = 1046038076233413876680986621738638966868902190991554511891709431142926821179422307244746230382433945021363558520372439295018128820530515472036158797508375
4n  = 8747185035038982590352709040026122318881751481045969499780427282145739554557145347428163122801488496160428126673378817922050559571378731528689279527994219
5r  = 1333932344710022001826837667329537548527
6
7A  = (n - 1) // r
8s  = A % r                 # = x + y  (since x+y < r)
9xy = (A - s) // r          # = x * y
10
11disc = s*s - 4*xy
12t    = math.isqrt(disc)    # = x - y
13x, y = (s + t)//2, (s - t)//2
14
15p, q = x*r + 1, y*r + 1
16assert p*q == n
17
18phi = (p - 1) * (q - 1)
19d   = pow(65537, -1, phi)
20m   = pow(ct, d, n)
21print(m.to_bytes((m.bit_length()+7)//8, "big").decode())

Output:

output
SkillBit{aLLLways_th3_w4yy}

The recovered plaintext is the challenge's own RSA plaintext (correct SkillBit{ prefix) and the factors multiply back to n - a structural , not a guess.

4. Flag

output
SkillBit{aLLLways_th3_w4yy}

("always the way" - and yes, the four L's and the pun on lattice-free factoring are the author's.)