Or search by topic
Published 2004 Revised 2021
You might like to try putting the ideas in this article into practice using this Public Key Cryptography Interactivity.
Public Key Cryptography, which is also known as asymmetric cryptography, is a system which uses a pair of keys, one to encode messages (which is a public key) and one to decode messages (the private key).
Before reading this article you might like to investigate these problems:
The set-up
(Alice, Bob and Eve are the traditional characters used when describing cryptographic systems)
These sorts of systems are called asymmetric as you cannot decode the message by reversing the process of encoding it. They make use of mathematical one-way functions.They are extensively used by everyone who sends any sort of information over the internet!
One of the oldest Public Key Cryptosystems is RSA, named after Ron Rivest, Adi Shamir and Leonard Adleman, who publicised their system in 1977. The same system was developed secretly in 1973 at GCHQ by Clifford Cocks. In 1997 Cocks' system was declassified.
This particular algorithm uses modular arithmetic to create a one-way function. For example, consider encoding the number $2$ by cubing it.
When we are working modulo $5$, it doesn't take very long to test all of the cases and "crack the code", but with "real-life" cryptography the modulus will be hundreds (maybe thousands) of digits long, and so testing every value will be impractical.
RSA cryptography uses the fact that an equation of the form $ax \equiv b \text{ mod }n$ has a unique solution if $a$ is co-prime* to $n$ (this idea is explored in More Adventures with Modular Arithmetic).
It also makes use of the "Fermat Euler theorem" which states that if $x$ and $n$ are co-prime* then:$$x^{\phi(n)} \equiv 1 \text{ mod }n$$
*Co-prime means that they have no common factors except for 1.
If you haven't met $\phi (n)$ or explored the problem Euler's Totient Function, then this might be a good time to do so!
Let's think about why this works. Alice encoded her message $M$ and sent $Q=M^e$ to Bob.
Bob is evaluating $Q^d \text{ mod }n$ which is equal to $(M^e)^d=M^{ed} \text{ mod }n$.
Bob has found the value $d$ so that $ed=k \phi(n) + 1$.
This means that we have:
\begin{align}
Q^d &\text{ mod } n \\
=M^{ed} &\text{ mod } n \qquad \text{ since } Q=M^e\\
=M^{k \phi(n) + 1} &\text{ mod } n \qquad \text{since } ed=k \phi(n) + 1\\
=M \times M^{k \phi(n)} &\text{ mod } n \qquad \text{ using the laws of indices}\\
=M \times [M^{\phi(n)}]^k &\text{ mod }n \qquad \text{ using the laws of indices}\\
=M \times 1 &\text{ mod }n \qquad \text{using the Fermat Euler theorem}\\
=M &\text{ mod }n
\end{align}
In the following example above, and in the one below, we used small primes so that it is easier to follow. In practice the primes would be very big.
Another example
To save you scrolling back up, here is the power mod calculator again.
Use the power mod calculator with $d=11$ and $n=221$ to decode 197 84 205 61 1 1 82 to check that you get the original message 20 50 69 3 1 1 10 = Cat2009.
Use the power mod calculator to encode the phrase "Hello" using the values $n=77$ and $e=13$.
Use the power mod calculator to decode the message 62 69 29 4 54 19 using the values $d=37$ and $n=77$.
You might like to try putting the ideas in this article into practice using this Public Key Cryptography Interactivity.
Disclaimer - Encoding letter by letter (as we have done in this article) is a bad idea as the code could then be broken by the use of frequency analysis. In real life a whole string of characters (i.e. the message) is converted into a long string of numbers without commas and gaps (possibly using ASCII), and then this long number is encoded in one go using the RSA algorithm.
There are a couple of ways in which this code can be "cracked" and how Eve could find the messages.
One way that Eve could break the code is by factorising $n$ and then finding $\phi(n)$. This would mean that she could then find the $d$ that solves $ed \equiv 1 \text{ mod }n$.
Alternatively Eve could take all of the values of $ 0<x<n-1$ and evaluate $x^e \text{ mod }n$ and see which matches the code.
The security of the system is based on using very large primes, which make both methods of breaking the code impractical. Computers can find the product of 2 very large primes quickly, but factorising into the product of two primes is much more difficult. As computers have got faster over the years the size of the primes used in RSA cryptosystems has had to increase. There are some concerns about what the advent of quantum computing might mean for public key cryptosystems.
Using an asymmetric cryptographic system needs quite a lot of computing power, and often it is used as part of a Hybrid Cryptosystem where an asymmetric cryptosystem is used to encode a key for a symmetric cryptosystem, which is used to encode the body of the message.
Further Reading:
Plus article "Safety in Numbers"
Simon Singh "The Code Book"
Chalkdust article "Clifford Cocks"
We are very grateful to the Heilbronn Institute for Mathematical Research for their generous support for the development of this resource.
In turn 4 people throw away three nuts from a pile and hide a quarter of the remainder finally leaving a multiple of 4 nuts. How many nuts were at the start?
Find the smallest numbers a, b, and c such that: a^2 = 2b^3 = 3c^5 What can you say about other solutions to this problem?