Given integers $N$ (modulus), $e$ (public exponent), and $d$ (private exponent), how would I find the primes $p$ and $q$ that compose $N$? I'm trying to do this in Python. This is homework.
Asked
Active
Viewed 1,884 times
-1
-
Dupe https://crypto.stackexchange.com/questions/11509/computing-p-and-q-from-private-key and https://crypto.stackexchange.com/questions/22374/factors-of-rsa-modulus (except the specific programming language, which is offtopic for crypto) – dave_thompson_085 Dec 04 '17 at 22:04
1 Answers
0
If you want to recover the primes $p,q$ from $(N,e,d),$ note that $L = ed - 1$ is a multiple of the Carmichael function $\lambda(N).$
Assuming your data is from a valid RSA setting, then $N$ is odd and square-free and there is a probabilistic algorithm to compute $p,q$ from $N,L\;$ see e.g. the solutions for J. v. zur Gathen, J. Gerhard, Modern computer algebra, 2nd ed., 2003: Algorithm 18.16 (Special integer factorization) in https://cosec.bit.uni-bonn.de/fileadmin/user_upload/science/mca/solutions.pdf.
BTW: You can't factor primes (or the factorization is trivial).

e-sushi
- 17,891
- 12
- 83
- 229

gammatester
- 1,005
- 1
- 8
- 12