# RSA example-calculation: Public Key = Private Key (e = d)

I am a bit confused. I just calculated manually the single steps of RSA for an implementation with small numbers and suddenly $d$ was equal $e$. Please help me understand what I am doing wrong.

Here’s my example:

1. I chose: $q = 7$ and $p = 11$
2. $N = 77$
3. $phi(N) = 60$
4. I chose: $e = 29$
5. $e \times d + k \times phi(N) = 1 \rightarrow$ Extended Euclidean algorithm
$$k = -14\\ d = 29$$

Test: $29 \times 29 + (-14) \times 60 = 1$

Where is the mistake?

• There is no mistake. In your toy example it just !accidentially! happens that $e$ is self-inverse, i.e., it happens that $e=d$. – DrLecter Jun 25 '14 at 16:45
• No mistake. A number can be it's own inverse. Just pick a different $e$. – mikeazo Jun 25 '14 at 16:45
• Note that $e$ cannot be its own inverse unless $e > \sqrt{\varphi(n)}$ (or $\lambda(n)$), or $e = 1$ of course, so in real usage with a normal public exponent $e$ this cannot happen. – Thomas Jun 26 '14 at 1:26
• Have a look here, that's the same problem with different numbers ($e=d=5, N=15,\phi(N)=12$) – tylo Jun 26 '14 at 13:04
• @tylo maybe these two represent classmates separated by a year in school :) – mikeazo Jun 26 '14 at 19:48

The only reason you are seeing this is because you are dealing with such small primes. With primes like we would use in practice (1024 bits), the probability of this happening is very, very small. And, it can only happen when $e>\sqrt{\lambda(n)}$. Since we typically use $e=65537$ in practice, it is guaranteed to not happen.
Anyways, there is no mistake in your calculations, you just happened to pick an $e$ which is its own inverse.
• Actually, the correct condition is $e > \sqrt{\lambda(n)}$. For a quick counterexample of your condition, consider $n = 2501$ and $e=11$. Here, $e=11 < \sqrt{\phi(n)} = \sqrt{2400}$ – poncho Jun 27 '14 at 13:24
• @poncho, thanks! Updated accordingly. I always forget about $\lambda$ when thinking about RSA. – mikeazo Jun 27 '14 at 13:27