reading-notes

View project on GitHub

Encryption, decryption, and cracking

One of the earliest encryption techniques is the Caesar Cipher, invented by Julius Caesar more than two thousand years ago to communicate messages to his allies. The Caesar Cipher is a great introduction to encryption, decryption, and code cracking, thanks to its simplicity.

Encrypting a message

Imagine Caesar wants to send this message:

SECRET MEETING AT THE PALACE

Here’s what that might look like encrypted:

YKIXKZ SKKZOTM GZ ZNK VGRGIK

The Caesar Cipher is a simple substitution cipher which replaces each original letter with a different letter in the alphabet by shifting the alphabet by a certain amount.

To make the encrypted message above, I shifted the alphabet by 6 and used this substitution table:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

G H I J K L M N O P Q R S T U V W X Y Z A B C D E F

Decrypting a message

According to historical records, Caesar always used a shift of 3. As long as his message recipient knew the shift amount, it was trivial for them to decode the message.

Imagine Caesar sends this message to a comrade:

EHZDUH EUXWXV

The comrade uses this substitution table, where the alphabet is shifted by 3:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

D E F G H I J K L M N O P Q R S T U V W X Y Z A B C

They can then decode the message with certainty. The first letter “E” was shifted by 3 from “B”, the second letter “H” was shifted by 3 from “E”, etc.

The result is this ominous message:

BEWARE BRUTUS

Cracking the cipher

Imagine that a very literate and savvy enemy intercepts one of Caesar’s messages.

RZ VMZ WMDIBDIB VGG AJMXZN OJ EJDI RDOC XGZJKVOMV OJ

YZAZVO OCZ ZIZHT LPZZI VO OCZ IDGZ YZGOV

That enemy does not know that Caesar always uses a shift of 3, so he must attempt to “crack” the cipher without knowing the shift.

There are three main techniques he could use: frequency analysis, known plaintext, and brute force.

Frequency analysis

Human languages tend to use some letters more than others. For example, “E” is the most popular letter in the English language. We can analyze the frequency of the characters in the message and identify the most likely “E” and narrow down the possible shift amounts based on that.

Known plaintext

Another term for the original unencrypted message is plaintext. If the enemy already knew some part of the plaintext, it will be easier for them to crack the rest of the encrypted version.

Brute force

There are only 25 possible shifts (not 26 — why not?). The enemy could take some time to try out each of them and find one that yielded a sensible message. They wouldn’t even need to try the shifts on the entire message, just the first word or two.

Encryption, decryption, and cracking

The three key aspects of data encryption:

  • Encryption: scrambling the data according to a secret key (in this case, the alphabet shift).
  • Decryption: recovering the original data from scrambled data by using the secret key.
  • Code cracking: uncovering the original data without knowing the secret, by using a variety of clever techniques.

Caesar cipher

In cryptography, a Caesar cipher, also known as Caesar’s cipher, the shift cipher, Caesar’s code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would become B, and so on. The method is named after Julius Caesar, who used it in his private correspondence.

The encryption step performed by a Caesar cipher is often incorporated as part of more complex schemes, such as the Vigenère cipher, and still has modern application in the ROT13 system. As with all single-alphabet substitution ciphers, the Caesar cipher is easily broken and in modern practice offers essentially no communications security.

The transformation can be represented by aligning two alphabets; the cipher alphabet is the plain alphabet rotated left or right by some number of positions. For instance, here is a Caesar cipher using a left rotation of three places, equivalent to a right shift of 23 (the shift parameter is used as the key):

Plain A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Cipher X Y Z A B C D E F G H I J K L M N O P Q R S T U V W

When encrypting, a person looks up each letter of the message in the “plain” line and writes down the corresponding letter in the “cipher” line.

Plaintext: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG Ciphertext: QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD

Deciphering is done in reverse, with a right shift of 3.