Cryptography

Challenge
Link

WELCOME RSA (100 pts)

WELCOME RSA (100 pts)

Description

-

Solution

Given source code below

#!/usr/bin/python3

from Crypto.Util.number import getPrime
from Crypto.Util.number import bytes_to_long

N = 1024
p = getPrime(N)
q = getPrime(N)

m = 0
with open('flag.txt', 'rb') as f:
    m = bytes_to_long(f.read())
e = 65537

phi = (p-1) * (q-1)
c_p = pow(m, e, p)
c_q = pow(m, e, q)

print(f"c_p = {c_p}")
print(f"c_q = {c_q}")
print(f"N = {p * q}")
print(f"phi = {phi}")

What we have:

  • c_p = m^e mod p

  • c_q = m^e mod q

  • n = p * q

  • phi = (p-1)*(q-1)

We can get p and q by utilizing phi and n

(pβˆ’1)(qβˆ’1)=pqβˆ’pβˆ’q+1(pβˆ’1)(qβˆ’1)=nβˆ’(p+q)+1p+q=nβˆ’phi+1(p-1)(q-1) = pq - p - q + 1\\ (p-1)(q-1) = n - (p + q) + 1\\ p + q = n - phi + 1

After getting p+q we can put it on quadratic equation

x2βˆ’bx+c=0x2βˆ’(p+q)x+pq=0x^2 - bx + c = 0\\ x^2 - (p+q)x + pq = 0

Finally, with asumption that m < p, we can decrypt it by only using p.

Flag: ASCIS{W3lc0me_t0_th3_P4rty_8597b0394054835f80ebd573a238ddbe1d86942657a59a7b6f84660d629472b5}

Last updated