how to decrypt if p=q in RSA [duplicate]

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

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.

• d = modinv(e,(p-1)*(q-1))?if p =q , it can't get the correct plaintext – sssqqq Jun 5 at 16:23
• Why is this a problem, should work the same way. – Meir Maor Jun 5 at 16:36
• m = 7,p = q = 13,e = 5, so c = pow(m,e,pq) = 76,can calculate d = 29,but pow(c,d,pq) = 33 – sssqqq Jun 5 at 16:57
• notice 33 mod 13 = 7. – Meir Maor Jun 5 at 17:07
• 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$ – Bissi Jun 5 at 17:10