redpwnCTF 2020 Crypto

4k RSA

This is a classic RSA question where we were given n e and c. In this case to decipher c we need to find d which is the modular inverse of the totient and e.

Finding the Totient

To find the Eulers Totient we need to find the factors of n. Then we could put it in this equation since we know that all of n's factors are prime

phi = (p0-1)(p1-1)...(pn-1)

To factor a large number like n we could of course use the Python Crypto module but we can search for the number on factordb.

Prime Factorization

We input n into factordb and indeed it is already FF(fully factored)


This is the prime factorization of n


To find the totient phi, and find the final plaintext, I wrote a small python script to automate the process. I skipped the RSA values as they take up to much space. They could be sound in the provided txt file.

from Crypto.Util.number import inverse
n= #n from provided txt file
c= #c from provided txt file
primes= #the primes listed above. Don't want to showcase twice as there is quite a lot of them.
for x in primes:
d = inverse(e,phi)

Essentially, we set phi to one and multiply it to the next prime factor of n minus one. Then we get d by doing the modular inverse of the public exponent and phi. To solve the plaintext, we just need to raise c to the power of d mod n.