This question already has an answer here:

p,q should be different,but if I let p = q,and encrypt the plaintext,then I can't decrypt it,so can decrypt it?


marked as duplicate by AleksanderRas, Ilmari Karonen, kelalaka, Squeamish Ossifrage, Ella Rose Jun 8 at 1:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


if p=q all you need to do is calculate square root of N. This is not any fancy arithmatic over some strange field just calculate square root of N normally(over R) and the solution will of course be the integer p=q.

Once yimou know p and q you also no Phi(n) and can calculate the private exponent using extented eucleadean algorithm.

  • $\begingroup$ d = modinv(e,(p-1)*(q-1))?if p =q , it can't get the correct plaintext $\endgroup$ – sssqqq Jun 5 at 16:23
  • $\begingroup$ Why is this a problem, should work the same way. $\endgroup$ – Meir Maor Jun 5 at 16:36
  • $\begingroup$ m = 7,p = q = 13,e = 5, so c = pow(m,e,pq) = 76,can calculate d = 29,but pow(c,d,pq) = 33 $\endgroup$ – sssqqq Jun 5 at 16:57
  • $\begingroup$ notice 33 mod 13 = 7. $\endgroup$ – Meir Maor Jun 5 at 17:07
  • 3
    $\begingroup$ if $p=q$ then $n=p^2$ and $\varphi(n)=p \cdot (p-1)$. In your example it gives $d=5^{-1} \mod 13 \cdot 12 =125$. Thus we have $76^{125} \mod 169 = 7$ $\endgroup$ – Bissi Jun 5 at 17:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.