Modern encryptions simply explained.
By: Prashant Shukla
Tags: Enigma, Encryption, Aes, Security, Technology

What to expect from this article?

This article explains how encryption works in plain language. We’ll start from a straightforward concept, and then we’ll slowly add complexity to encryption concepts, all the way to modern encryption technologies. Near the end of the article, we’ll see some historical references and how things evolved. This article does not go into any implementation details and instead stays at the concept level.

Terminologies

Plain text — A text that we want to encrypt.

Ciphertext — An encrypted text.

A straightforward encryption

Let’s start with a very, very simple algorithm. For simplicity, let’s take a straightforward, plain text, “HELLO.” One approach is to shift the whole word by 2 positions, right, so HELLO becomes “LOHEL.” Do you see a pun in the title :)? Moving letters right is way too simple. Let’s take another algorithm to shift every letter by 3 positions in the alphabet table. So, A becomes D, B becomes E, and so on. With this approach, “HELLO” becomes “KHOOR.”

In this approach, the algorithm shifts letters, and the “Key” is 3 because, in this example, we are shifting by 3. We can shift by 5 or 8 or any other reasonable number. To decrypt this message, any other party needs 2 information, 1- the algorithm, which is primarily public information, 2 — the key, which is to shift by how much. The key is secret information between sender and receiver. You must be thinking this is not secure enough, and you are right, and no one would want to send their credit card information over the internet using this approach. Do not underestimate this simple algorithm though. Julius Caesar used this approach. In this article, step by step, we’ll understand the concepts of modern encryption algorithms. However, before that, let us know why this approach is fragile and easy to crack.

What are the major problems with our simple encryption approach?

Because the algorithm is known to everyone, this will require a simple trial and error method to decrypt. Let’s say first we try with Key=1. We will unshift every letter by 1. So, unshift of K by 1 will give J, unshift of H by 1 will give G, and so on. By this approach, the decryption of our ciphertext “KHOOR” with key “1” will provide us with “JGNNQ.” While this could be an original plain text, but the text does not appear to be any familiar message. Let’s try with key=2. We’ll get “IHMMP,” again possible, but not standard text. Let’s try with 3, and the decrypted message is “HELLO.” Bingo, the plain text “HELLO” looks familiar, and most likely, the key is 3. It just took 3 attempts to crack it because the key and algorithm were too simple.

A little improved approach

Let’s improve the approach here a little bit. Rather than using a single shift key, let’s make 4 digit key, say 2135. The approach is similar. Instead of shifting every letter by a single number, this time, letters are shifted based on different digits of the key. For example, H → 2 = J, E→ 1 = F, L → 3 = O, L → 5 = Q, O → 2 = Q. For the last letter O, we are reusing 2 as the key because HELLO has 5 letters, and the key is 4 digits; we are starting with the first digit of the key again. With this approach, the ciphertext is “JFOQQ.” This one is a bit harder to crack because it’ll take 10*10*10*10=10000 possible combinations. For a 50 digit key, the number of possible combinations is huge.

What are the major problems with our little improved encryption approach?

While it’s tough to crack using the simple brute force method, this approach is susceptible to statistical analysis. To understand this better, let’s encrypt another similar-looking plain text, “FELLO.” Only one letter changed from H to F. The encryption of F→2 = H, and the complete ciphertext is “HFOQQ.” A careful observation of ciphertext “JFOQQ” and “HFOQQ” reveals that both the words are similar looking. A good encryption algorithm should make a considerable difference in ciphertext for a slight change in plain text. Otherwise, it is easy to find the patterns in the ciphertexts and reverse engineer the key.

A sophisticated encryption

We learned above that we want to avoid statistical analysis in the ciphertext. More complex patterns called “Substitution and Permutation” are used to avoid statistical analysis. In plain language, a lot of jumbling and shaking of letters of a pain text. Step 1 — Every letter is replaced with another letter using a predefined replacement rule. For example, A is replaced with T, B is replaced with P, T is replaced with C, etc. Step 2 — Change the position of letters in plain text. For example, position 1 is moved to 3, and position 3 is moved to 8, position 8 is moved to 2, and so on. We want to keep a sane boundary in which we are going to change the position of letters. We do not wish to replace position 6 with 1231. Let’s say 128, so, all substitution and permutations happen in this boundary of 128 only. This is called block “Substitution and Permutation.” Step 3 — Encrypt the message with the key. Hmmm…. you must be thinking that “yeah, it is a little bit of improvement, but has it jumbled letters enough to hide any pattern?” You are right. However, the algorithm does those three steps few more times, let us say ten more times to make complex jumbling. Note the user’s secret key is used in every iteration of substitution and permutation, making it tougher to reverse the process without knowing the key itself. After ten iterations, the ciphertext is so much more garbled that it is extremely hard to find any pattern.

Example of sophisticated encryption

Let’s go back to our example of “HELLO” and “FELLO” to understand the above concept more practically. In the first iteration, in “HELLO,” the H will be replaced with, let’s say K, similarly, in “FELLO,” the “F” will be replaced with, let’s say “T”. All other letters will be replaced same way, finally “HELLO” → “FGMMA” and “FELLO” → “TGMMA.” Still, texts look very similar. Not much has happened so far. Step 2, jumble them with the same jumbling rule for both plain texts. “FGMMA” → “GMFAM” and “TGMMA” → “GMTAM”, still relatable you can see a pattern. Now encrypt it using the previous example key 2135. “GMFAM” → “HOIFO” and “GMTAM” → “INWFO”. So after step 3, “HELLO” becomes “HOIFO,” and “FELLO” becomes “INWFO.” Good!! Just after one iteration, ciphertext looks slightly different, the last two letters are the same, but the first three letters are changed. Doing the same thing over and over again will drift those two similar-looking patterns very far apart. After ten iterations, they’ll look completely different. We saw here just changing one letter created a vast difference. Why did this happen? Because during permutation step, when letters are changing their positions, they are encrypted with different letters of key and producing another encrypted letter. The encrypted letters are later substituted using substitution rules. When the same thing happens over and over again, the key-mixing step changes letters differently. It is not possible to reverse engineer even if you know the plain text. To understand it better, let’s say, after10th iteration encrypted letter is “I,” then you don’t know if it is the outcome of H → 1 = I or G → 2 = I or D →7 = I. So, you can’t tell ciphertext before the 10th iteration, and hence you don’t know ciphertext after the 9th iteration, and so on. The jumbling steps destroy any correlation between similar-looking plain texts. Let’s say after the 10th iteration, “HELLO” becomes “MJLXI” and “FELLO” becomes “ZBGYW.” Even if you know “HELLO” became “MJLXI,” you cannot guess the original key. Also, there is no way to relate the ciphertext “ZBGYW” and “MJLXI” has common letters in plain text.

Where is this sophisticated algorithm used?

The approach mentioned above is efficient if appropriately used. During World War 2, German forces were using the Enigma machine that had a similar mechanism. Enigma machine was considered unbreakable for a long time. Enigma was typewriter-looking physical hardware. Enigma has key- settings, and those key settings produce 159 million million million million key combinations. These days Enigma machine is easily breakable. With modern computers processing powers, it’s easy to do statistical analysis of Enigma. Later NSA and IBM jointly developed Data Encryption Standards aka DES in the late 1970s. In computers, to merge keys with plain text, the XOR operation is used rather than shifting letters, as shown in the very first example of this article. DES uses a 56-bit key, and with today’s modern high processing computers, the 56 bit is not big enough and breakable with brute force methods.

The ultimate encryption algorithm.

These days standard algorithm for the internet is Advance Encryption Algorithm, aka AES developed in 2001. This algorithm uses the above-discussed approach of substitution and permutation with a key size of 128, 192, or 256. Our example of “HELLO” is just a five-letter word, while the key size is 128. A padding approach is used to fill the remaining 123 bytes so that the key and the plain texts are of the same size. For permutations, this algorithm does row and column-based shift operations. There is a very carefully designed table for substitution steps. AES does 10, 12, or 14 iterations to permutation, substitution, and key-mixing for 128, 192, and 256-bit size keys. The final ciphertext is so much encrypted that it requires 1000s of supercomputers and 1000s of years to break. At the same time, it takes less than a millisecond to decipher using a proper key. There is no pattern in similar-looking plain texts. A real example of encrypting “HELLO” is “ZJnVAqc4+b/8VocXY8+grA” and “FELLO is “vvaE97ihSZoPBarN9pV+wg”, can you find any relation between ciphertexts while four letters in plain text are the same? If we increase the number of iterations from 14 to, let’s say, 50, then it is much harder to break. However, it’ll take longer to encrypt. The current standards of AES are a delicate balance of speed and security.

Conclusion

A good encryption algorithm properly encrypts the plain text as well as destroys any pattern in similar-looking texts. The algorithm should also not allow reverse engineering to find the key from plain text and ciphertext. During world war 2, Allies forces were able to break Enigma because they knew that the weather report was sent every day at 6 AM and the weather report had predictable words like “Weather.” A good algorithm should be very fast to encrypt and decrypt for any practical use. The algorithm should not leak key information from any padding used. The ciphertext of the single letter “A” will have 127 padded letters, and the algorithm should be robust enough not to leak any information from padding. A good algorithm should also support tougher encryption as key size increases. In AES, when the key size doubles from 128 to 256, the key combination exponentially grows by 3402823669209384634674607431768211456 times (2 to the power 128). These days AES is standard and so for less vulnerable to risks discussed above.