Classical Ciphers
Slide deck 2. Symmetric cipher model, cryptanalysis, Caesar, monoalphabetic, Playfair, Vigenère, autokey, one-time pad, transpositions, rotors and steganography.
Introduction to Cryptography: Classical CiphersWolfram U · Caesar, Vigenère, substitution and transposition ciphers, 7 min
Caesar Cipher (Part 2)Neso Academy · shift (Caesar) cipher with worked examples, 10 min
Playfair Cipher (Part 1)Neso Academy · Playfair key matrix and digraphs, 13 min
Playfair Cipher (Part 2)Neso Academy · Playfair encryption rules with examples, 11 minSymmetric encryptionSearch on YouTube
Basic ideaSearch on YouTube
Symmetric encryption is also called conventional, private-key, or single-key encryption. The sender and the recipient share a common key.
- All classical encryption algorithms are private-key.
- Symmetric encryption was the only type before the invention of public-key cryptography in the 1970s.
- It is by far the most widely used type.
TerminologySearch on YouTube
| Term | Meaning |
|---|---|
| Plaintext | Original message |
| Ciphertext | Coded message |
| Cipher | Algorithm for transforming plaintext to ciphertext |
| Key | Information used in the cipher, known only to sender and receiver |
| Encipher (encrypt) | Converting plaintext to ciphertext |
| Decipher (decrypt) | Recovering plaintext from ciphertext |
| Cryptography | Study of encryption principles and methods |
| Cryptanalysis (codebreaking) | Study of principles and methods of deciphering ciphertext without knowing the key |
| Cryptology | The field of both cryptography and cryptanalysis |
Symmetric cipher modelSearch on YouTube
The slide figure shows this flow:
- The plaintext input goes into the encryption algorithm (for example, DES).
- The transmitted ciphertext goes to the recipient.
- The decryption algorithm (the reverse of the encryption algorithm) gives the plaintext output.
Both algorithms use the secret key shared by sender and recipient.
There are two requirements for secure use of symmetric encryption:
- A strong encryption algorithm.
- A secret key known only to sender and receiver.
Mathematically:
The slides assume that the encryption algorithm is known. Thus security depends on the secrecy of the key. This implies a secure channel to distribute the key.
The key must not travel with the ciphertext over the same insecure channel. A key sent next to the ciphertext protects nothing.
Classifying cryptosystemsSearch on YouTube
Three properties characterize a cryptographic system:
| Property | Options |
|---|---|
| Type of encryption operations used | Substitution / transposition / product |
| Number of keys used | Single-key (private) / two-key (public) |
| Way in which plaintext is processed | Block / stream |
CryptanalysisSearch on YouTube
Two approachesSearch on YouTube
The objective of cryptanalysis is to recover the key, not only the message. There are two general approaches:
- Cryptanalytic attack: uses the structure of the algorithm and properties of the plaintext.
- Brute-force attack: tries every possible key.
Attack typesSearch on YouTube
| Attack | What the attacker has |
|---|---|
| Ciphertext only | Only the algorithm and the ciphertext. The attack is statistical. The attacker must know or identify the plaintext |
| Known plaintext | Known or suspected plaintext and its ciphertext |
| Chosen plaintext | Selects plaintext and obtains its ciphertext |
| Chosen ciphertext | Selects ciphertext and obtains its plaintext |
| Chosen text | Selects plaintext or ciphertext to encrypt or decrypt |
Slide order: ciphertext only, known plaintext, chosen plaintext, chosen ciphertext, chosen text. Hook: "Count Keys Cheap, Crypt Twice". Each step down the list gives the attacker more control.
Security levelsSearch on YouTube
| Level | Meaning |
|---|---|
| Unconditional security | No matter how much computer power or time is available, the cipher cannot be broken. The ciphertext gives insufficient information to uniquely determine the plaintext |
| Computational security | With limited computing resources, the cipher cannot be broken. For example, the time needed for the calculations is greater than the age of the universe |
Brute force searchSearch on YouTube
- It is always possible to try every key.
- It is the most basic attack. The work is proportional to the key size.
- The attacker must know or recognize the plaintext.
b-bit key: number of keys = 2^b
On average, the attacker tries half the keys: 2^(b-1)Substitution ciphersSearch on YouTube
Substitution principleSearch on YouTube
A substitution cipher replaces the letters of plaintext with other letters, numbers, or symbols. If the plaintext is a sequence of bits, substitution replaces plaintext bit patterns with ciphertext bit patterns.
Caesar cipherSearch on YouTube
The Caesar cipher is the earliest known substitution cipher. Julius Caesar used it. It is the first attested use of a cipher in military affairs. It replaces each letter by the letter three places down the alphabet.
plain: meet me after the toga party
cipher: PHHW PH DIWHU WKH WRJD SDUWB| 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 | 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 |
Give each letter a number: , , ..., . Then:
The Caesar cipher uses . Modulo arithmetic wraps around the alphabet: and .
Breaking the Caesar cipherSearch on YouTube
There are only 26 possible keys: shifts . The attack is a brute-force search. Try all shifts on the ciphertext. The attacker must recognize the plaintext when it appears.
Slide test: break olssv ovd hyl fvb. The key is . Shift each letter back by 7 to get hello how are you.
One letter: and . The double letter ss becomes ll, which fits the word "hello".
Monoalphabetic cipherSearch on YouTube
Shuffle (jumble) the letters arbitrarily instead of shifting the alphabet. Each plaintext letter maps to a different random ciphertext letter. Thus the key is 26 letters long.
| 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 | D K V Q F I B J W P E S C X H T M Y A U O L R G Z N |
Slide example: plaintext ifwewishtoreplaceletters encrypts to WIRFRWAJUHYFTSDVFSFUUFYA.
The number of keys is . With so many keys, the cipher seems secure. This is wrong. The problem is language characteristics.
Language redundancySearch on YouTube
Human languages are redundant. For example, th lrd s m shphrd shll nt wnt is readable without its vowels. Letters are not equally common:
- In English, E is by far the most common letter, followed by T, R, N, I, O, A, S.
- Z, J, K, Q, X are fairly rare.
- Tables of single, double, and triple letter frequencies exist for various languages.
The slide bar chart gives these English relative frequencies (%):
| Letter | % | Letter | % | Letter | % |
|---|---|---|---|---|---|
| A | 8.167 | J | 0.153 | S | 6.327 |
| B | 1.492 | K | 0.772 | T | 9.056 |
| C | 2.782 | L | 4.025 | U | 2.758 |
| D | 4.253 | M | 2.406 | V | 0.978 |
| E | 12.702 | N | 6.749 | W | 2.360 |
| F | 2.228 | O | 7.507 | X | 0.150 |
| G | 2.015 | P | 1.929 | Y | 1.974 |
| H | 6.094 | Q | 0.095 | Z | 0.074 |
| I | 6.996 | R | 5.987 |
Key concept: monoalphabetic substitution ciphers do not change relative letter frequencies. Calculate the letter frequencies of the ciphertext. Then compare the counts or plots against the known values.
Worked cryptanalysisSearch on YouTube
Ciphertext from the slide:
UZQSOVUOHXMOPVGPOZPEVSGZWSZOPFPESXUDBMETSXAIZ
VUEPHZHMDZSHZOWSFPAPPDTSVPQUZWYMXUZUHSX
EPYEPOPDZSZUFPOMBZWPFUPZHMDJUDTMOHMQ- Count the relative letter frequencies.
- Guess that P and Z are e and t.
- Guess that ZW is th, so ZWP is the.
- Continue with trial and error.
The final plaintext:
it was disclosed yesterday that several informal but
direct contacts have been made with political
representatives of the viet cong in moscowMonoalphabetic quizSearch on YouTube
The key maps the plain alphabet to the reversed alphabet:
| 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 | z y x w v u t s r q p o n m l k j i h g f e d c b a |
Encrypt attack at noon. The letters map as , , , , , . The result is zggzxp zg mllm, so the correct option is C.
Playfair cipherSearch on YouTube
BackgroundSearch on YouTube
Even the large number of keys in a monoalphabetic cipher gives no security. One way to improve security is to encrypt multiple letters. The Playfair cipher is an example. Charles Wheatstone invented it in 1854, but it is named after his friend Baron Playfair.
Key matrixSearch on YouTube
The key is a 5 × 5 matrix of letters based on a keyword:
- Fill in the letters of the keyword, without duplicates.
- Fill the rest of the matrix with the other letters.
- I and J share one cell.
Keyword MONARCHY:
| M | O | N | A | R |
| C | H | Y | B | D |
| E | F | G | I/J | K |
| L | P | Q | S | T |
| U | V | W | X | Z |
Encryption rulesSearch on YouTube
Encrypt the plaintext two letters at a time:
- Repeated letter in a pair: insert a filler such as
X.balloonbecomesba lx lo on. - Same row: replace each letter with the letter to its right. Wrap from the end back to the start.
arencrypts asRM. - Same column: replace each letter with the letter below it. Wrap from the bottom to the top.
muencrypts toCM. - Otherwise: replace each letter with the letter in its own row and in the column of the other letter.
hsencrypts toBP.eaencrypts toIMorJM.
Rule order: Filler, Row, Column, Rectangle. Hook: "First Round Choice Rules". The filler breaks repeats. The row slides right. The column drops down. The rectangle takes the other corners.
GUARDIAN quizSearch on YouTube
The slide gives this Playfair square for keyword guardian:
| G | U | A | R | D |
| I/J | N | B | C | E |
| F | H | K | L | M |
| O | P | Q | S | T |
| V | W | X | Y | Z |
Plaintext postponed attack becomes the pairs po st po ne da tx ta ck. The filler x separates the repeated t.
| Pair | Rule | Result |
|---|---|---|
| po | same row (row 4) | QP |
| st | same row (row 4) | TO |
| po | same row (row 4) | QP |
| ne | same row (row 2), e wraps to I | BI |
| da | same row (row 1), d wraps to G | GR |
| tx | rectangle | QZ |
| ta | rectangle | QD |
| ck | rectangle | BL |
Ciphertext: QPTOQPBIGRQZQDBL. This is option B.
Security of PlayfairSearch on YouTube
| Fact | Value |
|---|---|
| Number of digrams | |
| Frequency table needed | 676 entries (versus 26 for monoalphabetic) |
| Ciphertext needed | Correspondingly more |
| History | Widely used for many years, for example by the US and British military in WW1 |
| Weakness | It can be broken with a few hundred letters, because it keeps much of the plaintext structure |
Playfair hides single-letter frequencies, but digram frequencies remain. An attacker counts digrams and compares them with English digram statistics.
Polyalphabetic ciphersSearch on YouTube
PrincipleSearch on YouTube
Polyalphabetic substitution ciphers use multiple cipher alphabets. More alphabets make cryptanalysis harder and give a flatter frequency distribution. A key selects the alphabet for each letter of the message:
- Use each alphabet in turn.
- Repeat from the start after the end of the key.
Vigenère cipherSearch on YouTube
The Vigenère cipher is the simplest polyalphabetic substitution cipher. It is effectively multiple Caesar ciphers. The key has letters: . The -th key letter specifies the -th alphabet. After letters, the key repeats. Decryption works in reverse.
Here is the key letter above in the repeated key. The slide also shows the 26 × 26 Vigenère tableau. Row = key letter, column = plaintext letter.
To encrypt:
- Write the plaintext out.
- Write the keyword repeated above it.
- Use each key letter as a Caesar key for the plaintext letter below it.
Slide example, keyword deceptive ():
key: deceptivedeceptivedeceptive
plaintext: wearediscoveredsaveyourself
ciphertext: ZICVTWQNGRZGVTWAVZHCQYGLMGJFirst letter: , key , so . Ninth letter: , key , so .
Vigenère securitySearch on YouTube
- Each plaintext letter has multiple ciphertext letters, so the letter frequencies are obscured but not totally lost.
- Start with the letter frequencies. See if the text looks monoalphabetic or not.
- If not, find the number of alphabets . Then attack each alphabet separately.
Every -th ciphertext letter uses the same Caesar alphabet. Split the ciphertext into streams. Then do a frequency attack on each stream.
Autokey cipherSearch on YouTube
Ideally, the key is as long as the message. Vigenère proposed the autokey cipher. The keyword is prefixed to the message to make the key.
key: deceptivewearediscoveredsav
plaintext: wearediscoveredsaveyourself
ciphertext: ZICVTWQNGKZEIIGASXSTSLVVWLAThe keyword recovers the first few letters. The recovered letters then decrypt the rest of the message. But the frequency characteristics remain for an attack.
One-time padSearch on YouTube
If a truly random key as long as the message is used, the cipher is secure. This is the one-time pad.
| Property | Detail |
|---|---|
| Unbreakable | The ciphertext bears no statistical relationship to the plaintext |
| Reason | For any plaintext and any ciphertext, a key exists that maps one to the other |
| Limit | The key can be used only once |
| Problems | Generation and safe distribution of the key |
The one-time pad has unconditional security only with a truly random key that is used once. Key reuse destroys the security.
Transposition ciphersSearch on YouTube
PrincipleSearch on YouTube
Classical transposition (permutation) ciphers hide the message by rearranging the letter order. They do not change the letters. Thus the ciphertext has the same frequency distribution as the original text, and this identifies a transposition cipher.
Substitution: new letters, same positions. Transposition: same letters, new positions. Hook: "Substitution Swops symbols, Transposition Turns order".
Rail fence cipherSearch on YouTube
Write the message letters diagonally over a number of rows. Then read off the cipher row by row. Slide example with 2 rows:
m e m a t r h t g p r y
e t e f e t e o a a tCiphertext: MEMATRHTGPRYETEFETEOAAT.
The plaintext meetmeafterthetogaparty has 23 letters. The top row holds the 12 odd-position letters. The bottom row holds the 11 even-position letters.
Row transposition cipherSearch on YouTube
This is a more complex transposition:
- Write the message in rows over a specified number of columns.
- Reorder the columns according to a key.
- Read off the columns in key order.
Slide example, key 4 3 1 2 5 6 7. The padding is xyz.
| Key | 4 | 3 | 1 | 2 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| Row 1 | a | t | t | a | c | k | p |
| Row 2 | o | s | t | p | o | n | e |
| Row 3 | d | u | n | t | i | l | t |
| Row 4 | w | o | a | m | x | y | z |
Read the column with label 1 first, then label 2, and so on:
| Label | Column letters |
|---|---|
| 1 | TTNA |
| 2 | APTM |
| 3 | TSUO |
| 4 | AODW |
| 5 | COIX |
| 6 | KNLY |
| 7 | PETZ |
Ciphertext: TTNAAPTMTSUOAODWCOIXKNLYPETZ.
Product and rotor ciphersSearch on YouTube
Product ciphersSearch on YouTube
Ciphers that use substitutions or transpositions are not secure because of language characteristics. So use several ciphers in succession:
- Two substitutions make a more complex substitution.
- Two transpositions make a more complex transposition.
- A substitution followed by a transposition makes a new, much harder cipher.
This is the bridge from classical to modern ciphers.
Substitution scrambles the letters. Transposition scrambles the positions. Together, each hides the structure of the other. Modern block ciphers use this idea over many rounds.
Rotor machinesSearch on YouTube
Before modern ciphers, rotor machines were the most common complex ciphers in use. They were widely used in WW2: the German Enigma, the Allied Hagelin, and the Japanese Purple.
- A rotor machine implements a very complex, varying substitution cipher.
- It uses a series of cylinders. Each cylinder gives one substitution.
- The cylinders rotate and change after each letter is encrypted.
The slides show a photo of a Hagelin rotor machine. They also show Figure 2.8, "Three-Rotor Machine With Wiring Represented by Numbered Contacts". The figure has a fast rotor, a medium rotor, and a slow rotor. Part (a) shows the initial setting. Part (b) shows the setting after one keystroke.
Exam number: three cylinders give alphabets. In general, cylinders give alphabets.
SteganographySearch on YouTube
Basic techniquesSearch on YouTube
Steganography is an alternative to encryption. It hides the existence of the message:
- Use only a subset of the letters or words of a longer message, marked in some way.
- Use invisible ink.
- Hide data in the LSB of a graphic image or sound file.
The drawback: high overhead to hide relatively few information bits.
Other techniquesSearch on YouTube
| Technique | How it works |
|---|---|
| Character marking | Selected letters of printed or typewritten text are over-written in pencil. The marks are not visible unless the paper is held at an angle to bright light |
| Invisible ink | A number of substances leave no visible trace until heat or some chemical is applied to the paper |
| Pin punctures | Small pin punctures on selected letters are not visible unless the paper is held up in front of a light |
| Typewriter correction ribbon | Used between lines typed with a black ribbon. The text typed with the correction tape is visible only under a strong light |
Cryptography hides the content of a message. Steganography hides the existence of a message.
Quick self-testSearch on YouTube
Write the two equations of the symmetric cipher model and name the two requirements.
and . The requirements are a strong encryption algorithm and a secret key known only to sender and receiver. The algorithm is assumed known, so a secure channel must distribute the key.
Give the three properties that characterize a cryptographic system.
Type of operations: substitution, transposition, or product. Number of keys: single-key (private) or two-key (public). Plaintext processing: block or stream.
List the five cryptanalytic attacks.
Ciphertext only, known plaintext, chosen plaintext, chosen ciphertext, and chosen text.
Differentiate unconditional and computational security.
Unconditional: the cipher cannot be broken with any amount of time or computer power. The ciphertext gives insufficient information to determine the plaintext. Computational: the cipher cannot be broken with limited computing resources, for example in less time than the age of the universe.
Encrypt "meet me after the toga party" with the Caesar cipher and state the decryption formula.
With : PHHW PH DIWHU WKH WRJD SDUWB. Decryption: , with to .
Break "olssv ovd hyl fvb" by brute force.
Try all 26 shifts. Shift back by 7 () to get "hello how are you".
Why is a monoalphabetic cipher insecure with 26! keys?
Language redundancy. The cipher keeps the relative letter frequencies. E (12.702%) and T (9.056%) are the most common English letters. So the attacker matches ciphertext frequencies to English and finds the substitution by trial and error.
Give the four Playfair rules with the MONARCHY examples.
Repeated letter: insert filler X ("balloon" becomes "ba lx lo on"). Same row: letter to the right ("ar" to "RM"). Same column: letter below ("mu" to "CM"). Otherwise: own row, column of the other letter ("hs" to "BP", "ea" to "IM" or "JM").
Encrypt "postponed attack" with Playfair keyword GUARDIAN.
Rows: GUARD / (I/J)NBCE / FHKLM / OPQST / VWXYZ. Pairs: po st po ne da tx ta ck. Ciphertext: QPTOQPBIGRQZQDBL (option B).
Encrypt "wearediscoveredsaveyourself" with keyword "deceptive", in Vigenère and in autokey.
Vigenère: ZICVTWQNGRZGVTWAVZHCQYGLMGJ. Autokey key: deceptivewearediscoveredsav. Autokey ciphertext: ZICVTWQNGKZEIIGASXSTSLVVWLA.
Why is the one-time pad unbreakable, and what are its problems?
The key is truly random, as long as the message, and used once. The ciphertext has no statistical relationship to the plaintext. For any plaintext and ciphertext, a key exists that maps one to the other. The problems are key generation and safe key distribution.
Give the rail fence and row transposition ciphertexts of the slide examples.
Rail fence (2 rows): MEMATRHTGPRYETEFETEOAAT. Row transposition with key 4312567: TTNAAPTMTSUOAODWCOIXKNLYPETZ.
How many alphabets do 3 rotor cylinders give?
alphabets. Each cylinder gives one substitution and rotates after each letter. Examples: German Enigma, Allied Hagelin, Japanese Purple.
- Symmetric encryption uses one shared key: , . The algorithm is known, so the key needs a secure distribution channel.
- Cryptanalysis tries to recover the key. The attack types are ciphertext only, known plaintext, chosen plaintext, chosen ciphertext, and chosen text.
- Caesar has 26 keys. The monoalphabetic cipher has keys, but frequency analysis breaks it.
- Playfair encrypts digrams in a 5 × 5 matrix. Vigenère uses multiple Caesar alphabets. Autokey adds the plaintext to the key. The one-time pad is unbreakable but impractical.
- Transpositions keep the letters and change the order. Product ciphers combine substitution and transposition.
- Three rotor cylinders give alphabets. Steganography hides the existence of a message.