Cryptography and encryption: basic concepts, an overview of ciphers and why we trust them
Cryptography is the science of encryption. The aim of encryption is to send someone a message in such a way that, apart from the sender, only its recipient can understand it, and nobody else.
Cryptography, coding, steganography
We will explain what cryptography is with an example, and along the way we will also explain the main differences between the related sciences: steganography and coding.
For our example, imagine that we have a beautiful wife, but an even more beautiful mistress, with whom we want to arrange a very romantic trip to the Blue Lagoon hotel.
-
First we agree with the mistress that we will send her messages by replacing every letter in the message with the next letter of the alphabet. So instead of “a” we write “b”, instead of “b” we write “c”, …, instead of “z” we write “a”. Instead of the word “ahoj” (Czech for “hi”) we would write “bipk”. So we could send our mistress the message
bipk lpdlp tfkefnf tf wfdfs b wzalpvtjnf qpmpiv nmflb b wpez
and our wife would have no idea what we are actually sending, whereas the mistress would: she would shift each letter back by one, so instead of “bipk lpdlp…” she would read “ahoj kočko…” (Czech for “hi, kitty…”; the full message reads “hi, kitty, we’ll meet in the evening and try out the position of milk and water”). At this point we are using cryptography (encryption). The trouble is that if you send your beautiful work colleague strange clumps of letters every other day, your wife will probably start to get nervous and before long she will pack your bags. Encryption is not the right choice in this case.
-
In the mistress’s case it will be better to choose steganography. The aim of steganography is to send someone a message that looks like an ordinary harmless message but has another, secret, message hidden in it. To our beautiful mistress we could send, for example, this message:
Zbývá ještě dodat, že kolikrát
i levné věci bývají kvalitní,
takže nemá smysl kupovat podle ceny.
Radši si přečtěte nějaké recenze
a rozhodněte se podle nich.(In English: “It remains to add that, often enough, even cheap things are good quality, so there is no point buying by price. You had better read some reviews and decide by them.” This text is in Czech, because the hidden word is Czech too.)
It looks fairly harmless, but if you read only the first letter of each line, you get the word “zítra” (Czech for “tomorrow”). That is the word hidden in the paragraph of text.
The difference from cryptography is thus mainly that the output of steganography is an ordinary-looking text/image/sound recording/…, which contains some hidden message, typically a much smaller one. With an encrypted text it is obvious at first glance that it is not an ordinary text. So you use a cipher when you do not need to hide the fact that you are communicating with someone, but you need to hide the content. You use steganography when you need to hide the very fact that you are communicating with someone.
-
Coding, in turn, is not about secrecy at all; it is only about rewriting a message into another form that happens to suit us. For example, we could rewrite the message into Morse code so that we could send the mistress a message … by flashing a torch. Subtlety itself. The aim of Morse code is not to “hide” the message, only to rewrite it into another form. Another code is the binary code that computers use: for example, each letter is first encoded in the computer as some number, and that number is then converted into the binary system and stored that way on the disk. The word “ahoj” would be stored in a computer as the binary notation of the numbers “097 104 111 106” (see the ASCII table). Again it is not about secrecy, just another way of writing.
Cryptanalysis
Almost no cipher is completely secure, and almost every one can be broken in time. It is only a matter of time, and if you use a cipher, you have to hope that the time will be long enough that you no longer mind that someone has read your message. The only exception is the Vernam cipher, which can be proved to be unbreakable. If your ex-wife were to break the ciphers you wrote to your mistress, it would probably not matter any more, since she is an ex-wife anyway.
The science that studies the ways of breaking a given cipher is called cryptanalysis. Cryptography deals with how to encrypt, and cryptanalysis is the evil little brother who deals with breaking. Both disciplines come under cryptology. So cryptology = cryptography + cryptanalysis. But often the word cryptography is simply used instead of cryptology.
Basic terms of cryptography
- Plaintext is the text that we want to encrypt and then send to someone. The plaintext could be, for example, “Let’s meet in the evening”.
- Ciphertext (or encrypted text) is the text you get by encrypting the plaintext.
- A key is a piece of information that the parties communicating with each other exchange over some secure channel. The key specifies how the cipher behaves. For example, instead of always shifting a letter by one place, that is, “a” -> “b”, “b” -> “c”, we can shift it by three places, that is, “a” -> “d”, “b” -> “e”. By the key we then mean the number of places by which we shift. A steganographic algorithm can have a key too. We need not take the first letter of every line, but could read, say, only the fifth letter of the line. The key would then be the number five.
- A cipher is an algorithm that takes a plaintext and a key as its input and returns an encrypted text as its output.
Why we believe a cipher is secure
As early as 1883 the Dutch linguist Auguste Kerckhoffs wrote down a rule that still holds today: a cipher must stay secure even if the enemy knows the whole procedure. Only the key should be secret. The procedures of modern ciphers are therefore public and are chosen in open competitions, in which cryptographers from all over the world try to break them.
But how can you tell that a cipher is secure? It can be proved only for the Vernam cipher. The American mathematician Claude Shannon showed in 1949 that without the key you can find out nothing at all from it. It encrypts by adding one letter of the key to each letter of the message. There is a catch: the key must be random, as long as the message, and can be used only once, so it is not very practical.
All the other ciphers that protect the internet today rest on some problem that we believe to be hard:
- the RSA cipher rests on the fact that a large number cannot be quickly factorised into primes,
- the Diffie–Hellman key exchange rests on the fact that you cannot find the exponent from the result of raising to a power,
- elliptic curves rest on the fact that from a multiple of a point you cannot tell how many times it was added,
- the main post-quantum ciphers rest on the fact that a system of equations with small errors cannot be solved.
For none of these problems has anybody proved that it is really hard. And so far it cannot even be done. If someone proved that one of them is hard, they would incidentally solve the famous P versus NP problem, which mathematicians have been trying in vain to crack for more than fifty years. The only proof of security is thus that enough clever people tried for a long time and did not succeed.
History shows that this is not an empty sentence. In 1977 Scientific American printed a message encrypted with the RSA cipher. The authors of the cipher estimated at the time that factorising the 129-digit number used would take 40 quadrillion years. In 1994 about 600 volunteers with 1,600 computers factorised it in roughly eight months. The message read “The magic words are squeamish ossifrage”. The estimate was wrong, because in the meantime mathematicians had devised much faster methods of factorising. The RSA cipher did not fall because of that; it was enough to start using longer numbers. Other ciphers were not so lucky. The American standard DES, with a 56-bit key, was cracked in 1998 by a special machine in 56 hours, and the cipher SIKE, a candidate for a post-quantum standard, was broken in 2022 by two mathematicians in an hour on a single ordinary computer.
Cryptographers therefore reckon that any cipher may one day meet a new attack. New ciphers are deployed alongside the old ones, so that the connection holds for as long as at least one of them holds out, and systems are designed so that a cipher can be replaced quickly.
Ciphers on matweb
Historical ciphers, starting with the simplest:
- the Atbash cipher, the Caesar cipher, the affine cipher and the substitution cipher replace each letter with another,
- the Polybius square, the pigpen cipher, the Playfair cipher and the ADFGVX cipher work with tables,
- the rail fence cipher and scytale and the turning grille merely rearrange the letters,
- the Vigenère cipher and the Vernam cipher encrypt with a longer key,
- Bacon’s cipher is more steganography than cipher, hiding the message in an ordinary text.
Codes that hide nothing: Morse code, the number cipher, the phone keypad cipher and flag semaphore.
How ciphers are cracked: frequency analysis, breaking the Caesar cipher by brute force, the key length of the Vigenère cipher, the Friedman test and breaking the Vigenère cipher.
Modern cryptography: the Diffie–Hellman key exchange, the RSA cipher, elliptic curves, Shor’s algorithm and post-quantum cryptography.