Classical ciphers convert plaintext into ciphertext, but lack strength and complexity for modern-day data security, hence more modern ciphers: DES, AES, and 3DES are utilized.
We have two basic components of classical ciphers:
- Substitution: letters are replaced by other letters e.g. Mono/Poly alphabetic ciphers
- Transposition: letters are arranged in different order
Monoalphabetic Ciphers
each character in the plaintext is replaced by exactly one fixed character in the ciphertext. The same letter in the plaintext always maps to the same letter in the ciphertext.
e.g. Caeser cipher
Polyalphabetic Ciphers
the same letter in the plaintext can be encrypted to different letters in the ciphertext, depending on its position in the message.
e.g. Playfair cipher, Vigenere cipher, hill cipher, one time pad cipher
1. Shift cipher / Caesar cipher
each letter in the plaintext is shifted by a certain number of positions in the alphabet

2. ROT13 (rotate by 13)
Each letter of the alphabet is shifted by 13 positions.

3. Substitution Cipher
Instead of shifting letters by a fixed amount (as in the Caesar cipher), a permutation cipher replaces each letter of the plaintext with another letter based on a random arrangement of the alphabet. You choose which letters to exchange from original alphabets.
- Original alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ
- Permuted alphabet: QWERTYUIOPLKJHGFDSAZXCVBNM
Monoalphabetic substitution example
| Plain alphabet | 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 alphabet | M | R | B | G | S | L | O | A | E | F | Y | W | D | K | U | Q | H | P | C | J | T | Z | V | X | I | N |
4. Vigenere Cipher
uses a keyword to determine the shift applied to each letter of the plaintext.
Vigenère tableau
| Key / plaintext | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| A | 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 |
| B | 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 | A |
| C | C | 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 |
| D | 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 |
| E | 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 | D |
| F | F | 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 |
| G | 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 |
| H | 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 | G |
| I | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H |
| J | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I |
| K | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J |
| L | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K |
| M | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L |
| N | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M |
| O | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M | N |
| P | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O |
| Q | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P |
| R | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q |
| S | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R |
| T | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S |
| U | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T |
| V | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U |
| W | W | 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 |
| X | 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 |
| Y | 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 | X |
| Z | Z | 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 |
FLOWER with the repeated key SUN
| Plaintext | F | L | O | W | E | R |
| Key | S | U | N | S | U | N |
| Ciphertext | X | F | B | Q | Y | E |
5. Transposition Cipher
Letters or symbols in the plaintext are rearranged according to a specific system or pattern, rather than being replaced by other characters (as in a substitution cipher)
Columnar transposition example
| 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 columns in ascending key order: column 3, column 4, column 2, column 1, column 5, column 6, then column 7. The final X, Y, and Z are padding.
TTNAAPTMTSUOAODWCOIXKNLYPETZ6. Rotor Machines (1870 - 1943)
Combines both substitution and transposition ciphers, Used by govt and army.
The machine encrypts messages by passing electrical signals through a series of rotating disks (rotors), each of which performs a letter substitution. After each letter is encrypted, the rotors advance, dynamically changing the substitution pattern for the next letter.
Enigma Machine: A well-known WWII rotor machine used by Nazi Germany, eventually decrypted by the Allies.
Breaking Monoalphabetic Ciphers
Monoalphabetic ciphers preserve frequency of alphabetic characters
frequency analysis is a powerful tool for breaking these ciphers. This technique relies on the fact that certain letters, pairs of letters (bigrams), or even groups of three letters (trigrams) appear with predictable frequency in natural languages.
common letters such as 'e', 't', 'a', 'o', 'i', and 'n' tend to appear more often.
English letter and digram frequencies
| Letter | Probability | Letter | Probability |
|---|---|---|---|
| a | 0.082 | n | 0.067 |
| b | 0.015 | o | 0.075 |
| c | 0.028 | p | 0.019 |
| d | 0.043 | q | 0.001 |
| e | 0.127 | r | 0.060 |
| f | 0.022 | s | 0.063 |
| g | 0.020 | t | 0.091 |
| h | 0.061 | u | 0.028 |
| i | 0.070 | v | 0.010 |
| j | 0.002 | w | 0.023 |
| k | 0.008 | x | 0.001 |
| l | 0.040 | y | 0.020 |
| m | 0.024 | z | 0.001 |
| Group | Letters | Approximate probability |
|---|---|---|
| 1 | E | 0.12 |
| 2 | T, A, O, I, N, S, H, R | 0.06–0.09 each |
| 3 | D, L | 0.04 each |
| 4 | C, U, M, W, F, G, Y, P, B | 0.015–0.028 each |
| 5 | V, K, J, X, Q, Z | 0.01 or less each |
| Digram | Frequency |
|---|---|
| th | 0.0315 |
| he | 0.0251 |
| an | 0.0172 |
| in | 0.0169 |
| er | 0.0154 |
| re | 0.0148 |
Breaking Vignere Ciphers
t's a combination of simple substitution ciphers where the rotations are determined by a repeating keyword.
Frequency analysis becomes possible if the length of the repeating key (period) is guessed.
Kasiski test:
Repeated sequences of letters in the ciphertext could indicate repeated use of the same key letters, revealing the key length.
Repeated-key example
| Key | ABCD | ABCD | ABCD | ABCD | ABCD | ABCD | ABCD |
| Plaintext | CRYP | TOIS | SHOR | TFOR | CRYP | TOGR | APHY |
| Ciphertext | CSAS | TPKV | SIQU | TGQU | CSAS | TPIU | AQJB |
The plaintext is “CRYPTO IS SHORT FOR CRYPTOGRAPHY.” Grouping into four-letter chunks exposes the period of the repeated key ABCD.
Repetitions of CSASTP is at a distance16
Assuming that the repeated segments represent the same plaintext segments,
this implies that the key is 16, 8, 4, 2, or 1 characters long
One Time Pad (OTP) with XOR
The plaintext is combined with a random key (or pad) that is the same length as the plaintext.
When used correctly, the OTP is mathematically impossible to decrypt the ciphertext without the key.
The key must be as long as the plaintext, making it impractical for large messages.
Distributing and managing the key securely can be challenging, especially for large amounts of data.
Trying all possible keys doesn't help you at all, because all possible plaintexts are equally likely decryptions of the ciphertext.
Plaintext: "WORLD"
Key: "ABCDE" (randomly generated)
Ciphertext Calculation:
W ⨁ A = V
O ⨁ B = O
R ⨁ C = O
L ⨁ D = H
D ⨁ E = A
Ciphertext: "VOOHA"
Bytewise XOR encryption example
| Plaintext / ASCII | Key / ASCII | XOR result (decimal) | Result (hex) |
|---|---|---|---|
| W / 87 | A / 65 | 87 XOR 65 = 22 | 16 |
| O / 79 | B / 66 | 79 XOR 66 = 13 | 0D |
| R / 82 | C / 67 | 82 XOR 67 = 17 | 11 |
| L / 76 | D / 68 | 76 XOR 68 = 8 | 08 |
| D / 68 | E / 69 | 68 XOR 69 = 1 | 01 |
These ciphertext bytes are control characters, not printable letters: SYN, CR, DC1, BS, and SOH. The original screenshot mixed ASCII and letter-based notation; the arithmetic here uses bytewise XOR consistently.
Bytewise XOR decryption example
| Ciphertext byte (decimal) | Key / ASCII | Recovered ASCII | Plaintext |
|---|---|---|---|
| 22 | A / 65 | 22 XOR 65 = 87 | W |
| 13 | B / 66 | 13 XOR 66 = 79 | O |
| 17 | C / 67 | 17 XOR 67 = 82 | R |
| 8 | D / 68 | 8 XOR 68 = 76 | L |
| 1 | E / 69 | 1 XOR 69 = 68 | D |
Stream cipher
encrypts plaintext one bit or byte at a time
Each bit or byte of plaintext is combined with a corresponding bit or byte from the key stream generated by the pseudorandom number generator (PRG)
This key stream is then XOR'd with the plaintext to produce ciphertext.
If the PRG is predictable, the security of the cipher is compromised.
Encryption:
Decryption:

Pseudorandom generators
In one-time pad, key must be as long as plaintext, which is impractical in real life
Stream Ciphers generate a long sequence of pseudorandom bits from s shorter, secret seed/key
PRG uses a deterministic algorithm, given same set of initial seed/key it wil always product same sequence of bits
PRG must be unpredictable
PRG is predictable if given (n-1) bits it can predict n bit
LCG is a weak PRG:
X = current value
a, c, m are constants
is the initial seed
The sequence can have a very short period depending on the parameters chosen
If an attacker knows a few outputs, they can easily determine the future outputs.
Attacks on Stream Cipher
By analyzing the resulting ciphertexts, an attacker might detect correlations or patterns that could lead to guessing parts of the plaintexts, making the encryption insecure.
- No integrity
The OTP does not provide any built-in mechanism to ensure the integrity of the ciphertext. This means that modifications to the ciphertext can go undetected. The modification will result in a predictable change in the plaintext.
Real-world Stream cipher examples
- RC4 cipher
RC4 was commonly used in protocols like HTTPS and WEP.
has known weaknesses, such as biases in the output (e.g., a specific probability for the second byte being zero). Attackers can exploit certain patterns in the key or output to deduce information.
- CSS (Content Scramble System)
CSS is a cryptographic system used for DVD encryption, employing linear feedback shift registers (LFSRs) for encryption.
CSS has been broken, particularly through a cryptanalysis technique that involves brute-forcing the initial settings of the LFSRs, allowing attackers to recover the encryption key and generate the output.
- Modern Stream Cipher: eStream
Focuses on developing secure stream ciphers. It uses a pseudorandom generator (PRG) that incorporates a nonce (a non-repeating value) for each key to ensure security. The pair (k,r) is never used more than once. - Modern Stream Cipher: Salsa20
It processes data in blocks and utilizes a fast invertible function.
Salsa20's architecture involves generating output based on the key and nonce, and it is structured to be efficient on x86 architectures. there are no known attacks against Salsa20 that are more effective than exhaustive search methods.