-1

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.

Squeamish Ossifrage
  • 49,816
  • 3
  • 122
  • 230

1 Answers1

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).

Mike Edward Moras
  • 18,161
  • 12
  • 87
  • 240
gammatester
  • 1,005
  • 1
  • 8
  • 12