Simple Substitution Algorithms
A substitution algorithm is a method of encryption where elements of the plaintext (the original message) are replaced with other symbols or characters. The main idea is:
Replace each letter or group of letters in a message with something else to obscure the original meaning.
ποΈ Classical Substitution Algorithms Letβs look at a few fundamental substitution algorithms that have been used historically and are still taught today for educational purposes.
- Caesar Cipher The Caesar Cipher is one of the simplest and most well-known substitution ciphers. It shifts each letter in the plaintext by a fixed number of positions down the alphabet.
π’ Example: Shift by 3:
Plaintext: HELLO
Ciphertext: KHOOR
π§ Encryption Formula: For each character:
E(x) = (x + n) mod 26
Where:
x is the position of the letter (0β25)
n is the shift amount (e.g., 3)
mod 26 wraps around the alphabet
π Decryption Formula:
D(x) = (x - n) mod 26
Caesar cipher is easy to break with brute-force since there are only 25 possible shifts.
- Monoalphabetic Substitution Instead of shifting letters, each letter of the alphabet is replaced by another fixed letter using a predefined substitution key.
π§Ύ Example: Suppose this mapping:
A β M, B β N, C β B, D β V, E β C, ..., Z β Q
Then:
Plaintext: ATTACK
Ciphertext: MBBMBO
Unlike Caesar, this cipher uses a completely shuffled alphabet, making it harder to brute-force but still vulnerable to frequency analysis.
- Atbash Cipher The Atbash cipher is a special kind of monoalphabetic cipher where the alphabet is reversed.
π Mapping:
A β Z, B β Y, C β X, ..., M β N
Example:
Plaintext: HELLO
Ciphertext: SVOOL
Atbash is very simple, and once you know itβs a reverse alphabet, itβs easy to decode.
- ROT13 Cipher The ROT13 cipher is a Caesar cipher with a shift of 13. Applying it twice restores the original text.
π Example:
Plaintext: HELLO
Ciphertext: URYYB
Apply ROT13 again:
Ciphertext: URYYB β HELLO
Used in forums to obscure spoilers or jokes. ROT13 is self-inverse.
π Weaknesses of Simple Substitution Ciphers While educational and historically important, simple substitution algorithms are not secure by modern standards.
Hereβs why:
Frequency analysis can reveal common letters (like E, T, A).
Brute-force is easy for Caesar (only 25 options).
Patterns in ciphertext can reveal word structure.
β Why Study Them? Even though theyβre outdated, simple substitution ciphers are important because they:
Teach core ideas of encryption and decryption
Help build intuition about symmetric key cryptography
Lay the groundwork for understanding modern cryptographic systems
π§ͺ Try It Yourself! You can implement a Caesar cipher in your favorite programming language. Hereβs a basic version in Python:
def caesar_encrypt(text, shift):
result = ''
for char in text.upper():
if char.isalpha():
result += chr((ord(char) - 65 + shift) % 26 + 65)
else:
result += char
return result
print(caesar_encrypt("HELLO WORLD", 3)) # Output: KHOOR ZRUOG π§© Conclusion Simple substitution algorithms may not secure your bank account, but they play a crucial role in understanding the evolution of cryptography. Theyβre fun to play with and reveal how encryption began thousands of years ago.
Up next, weβll look at polyalphabetic substitution (like the VigenΓ¨re cipher), which adds more complexity and security.