Why RSA Works
Learn the mathematical proof of why RSA works.
RSA encryption consists of taking a plaintext and computing , while decryption is given by . We now explain why these two operations ‘reverse’ one another.
We’ll assume is an RSA public key and is the corresponding private key. Sometimes we’ll use the notation to mean . We’ll also use a mathematical result attributed to Fermat, which states that for any number satisfying , it follows that:
Now, expressing the RSA decryption formula mathematically, we have:
Remember that because is the modular inverse of , we have . This means that there is some positive integer, , for which it’s true that:
By replacing this in our above expression for the decryption function, we get:
Now, all we do is rewrite this expression by rearranging the powers of . There are no mathematical tricks here. We follow the rules describing how the powers of a number behave, like so:
The above-mentioned mathematical result attributed to Fermat can now be used. Writing instead of , we see that as long as the greatest common divisor of and is 1, this result says:
Therefore, we see that:
This is what we hoped decryption would achieve.
The only case we haven’t covered is when is not equal to 1. Note that this is an extremely rare case and only happens in the highly unlikely event of either , for some , or , for some . If , then and so . In other words, .
Since is a multiple of , in this case, it can’t be a multiple of as well, and so the greatest common divisor of and is 1. So we can apply Fermat’s result and the above RSA argument to see that . We have now shown and . It follows by a simple number theory result that . If , we apply a similar argument to show the same result.
Get hands-on with 1400+ tech skills courses.