Skip to main content
  1. Resources/
  2. Study Materials/
  3. Information & Communication Technology Engineering/
  4. ICT Semester 5/
  5. Cyber Security (4353204)/

6 mins· ·
Milav Dabgar
Author
Milav Dabgar
Experienced lecturer in the electrical and electronic manufacturing industry. Skilled in Embedded Systems, Image Processing, Data Science, MATLAB, Python, STM32. Strong education professional with a Master’s degree in Communication Systems Engineering from L.D. College of Engineering - Ahmedabad.
Caesar Cipher

Caesar Cipher

The Foundation of Substitution Cryptography

Julius Caesar's Secret Communication Method

Caesar Cipher Mechanism

Historical Origins

Julius Caesar (100-44 BCE) used this cipher to communicate with his generals during military campaigns, shifting each letter by 3 positions in the alphabet.

Historical Context:

  • Roman Empire: Need for secure military communication
  • Literacy Rates: Most people couldn't read, adding security
  • Simple Implementation: Could be done by hand without tools
  • Effective for its Time: Adequate against contemporary threats

Caesar Cipher Definition

Caesar Cipher is a type of substitution cipher where each letter in the plaintext is shifted a certain number of places down or up the alphabet.

Key Characteristics:

  • Shift Cipher: Also known as shift cipher
  • Monoalphabetic: One alphabet used for entire message
  • Symmetric: Same key for encryption and decryption
  • Additive Cipher: Each letter replaced by letter k positions ahead

Caesar Cipher Algorithm

Encryption Formula:

C = (P + K) mod 26

  • C = Ciphertext letter position
  • P = Plaintext letter position (A=0, B=1, ..., Z=25)
  • K = Key (shift value)

Decryption Formula:

P = (C - K) mod 26

Alphabet Shift Example (K=3)

Original 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
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

Shifted Alphabet (Shift +3):
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
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 0 1 2

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

Encryption Example

Plaintext: "HELLO WORLD"
Key (Shift): 3

Step-by-step Encryption:
H (7) + 3 = 10 = K
E (4) + 3 = 7 = H
L (11) + 3 = 14 = O
L (11) + 3 = 14 = O
O (14) + 3 = 17 = R

W (22) + 3 = 25 = Z
O (14) + 3 = 17 = R
R (17) + 3 = 20 = U
L (11) + 3 = 14 = O
D (3) + 3 = 6 = G

Ciphertext: "KHOOR ZRUOG"

Decryption Example

Ciphertext: "KHOOR ZRUOG"
Key (Shift): 3

Step-by-step Decryption:
K (10) - 3 = 7 = H
H (7) - 3 = 4 = E
O (14) - 3 = 11 = L
O (14) - 3 = 11 = L
R (17) - 3 = 14 = O

Z (25) - 3 = 22 = W
R (17) - 3 = 14 = O
U (20) - 3 = 17 = R
O (14) - 3 = 11 = L
G (6) - 3 = 3 = D

Plaintext: "HELLO WORLD"

Handling Wrap-Around

Problem: What happens when we go past Z?
Example with Shift 3:

X (23) + 3 = 26 mod 26 = 0 = A
Y (24) + 3 = 27 mod 26 = 1 = B
Z (25) + 3 = 28 mod 26 = 2 = C

Decryption Wrap-Around:
A (0) - 3 = -3 mod 26 = 23 = X
B (1) - 3 = -2 mod 26 = 24 = Y
C (2) - 3 = -1 mod 26 = 25 = Z

Rule: If result is negative, add 26

Different Shift Values

Message: "ATTACK"

Shift 1: BUUBDL
Shift 5: FYYFHP
Shift 10: KDDKMU
Shift 13: NGGNPX (ROT13)
Shift 20: UFFUGE
Shift 25: ZSSZBJZ

Note: Shift 0 = original text
Note: Shift 26 = same as shift 0

ROT13 - Special Case

ROT13: Caesar cipher with shift of 13, has special property that encryption and decryption use the same operation.
Why ROT13 is Special:
26 ÷ 2 = 13

Applying ROT13 twice returns original text:
HELLO → URYYB → HELLO

Modern Uses:
• Hide spoilers in online forums
• Obscure potentially offensive content
• Simple text obfuscation
• Not for real security!

Programming Implementation

Python Implementation:

def caesar_encrypt(text, shift):
    result = ""
    for char in text:
        if char.isalpha():
            ascii_offset = 65 if char.isupper() else 97
            shifted = (ord(char) - ascii_offset + shift) % 26
            result += chr(shifted + ascii_offset)
        else:
            result += char
    return result

Usage:
caesar_encrypt("HELLO", 3) → "KHOOR"

Breaking Caesar Cipher

Frequency Analysis Attack:

  • Caesar cipher preserves letter frequencies
  • Most common letter in English is 'E'
  • Find most frequent letter in ciphertext
  • Calculate shift from 'E' to that letter
Example:
If 'H' is most frequent in ciphertext:
E → H means shift of 3
Try decryption with shift -3

Brute Force Attack

Small Key Space: Only 25 possible keys (excluding 0)
Ciphertext: "KHOOR"

Shift 1: JGNNQ
Shift 2: IFMMP
Shift 3: HELLO ← Readable!
Shift 4: GDKKN
Shift 5: FCJJM
...

Result: Can try all possibilities in seconds

Security Weaknesses

  • Small Key Space: Only 25 possible keys
  • Frequency Preservation: Statistical patterns maintained
  • Pattern Recognition: Word patterns remain visible
  • Known Plaintext: One word can reveal entire key
  • No Key Distribution: Key must be shared beforehand
Conclusion: Caesar cipher provides no real security against modern cryptanalysis

Caesar Cipher Variations

Historical Improvements:

  • Keyword Caesar: Shift based on keyword letters
  • Progressive Caesar: Increase shift for each letter
  • Random Caesar: Different shift for each letter
  • Affine Cipher: Combine shift with multiplication
Modern Context: These variations led to development of polyalphabetic ciphers like Vigenère

Educational Importance

Why Study Caesar Cipher?

  • Foundation Concepts: Introduces substitution cryptography
  • Modular Arithmetic: Teaches basic mathematical operations
  • Cryptanalysis: Simple to attack and understand weaknesses
  • Historical Context: Shows evolution of cryptography
  • Programming Practice: Easy to implement and experiment

Modern Uses

Legitimate Uses Today:

  • Education: Teaching cryptography basics
  • Puzzles: Word games and brain teasers
  • Obfuscation: Simple text hiding (not security)
  • CTF Competitions: Capture-the-flag challenges
Warning: Never use Caesar cipher for actual security purposes!

Try It Yourself

Exercise 1: Decrypt this message (Caesar cipher)
"WKH TXLFN EURZQ IRA"

Exercise 2: Encrypt your name with shift 5

Exercise 3: Find the key for this ciphertext:
"EBIIL ILDPH"
(Hint: Common greeting)

Tools:
• Online Caesar cipher tools
• Write your own program
• Do it by hand with alphabet wheel

Key Takeaways

  • Caesar cipher is simplest form of substitution cipher
  • Uses fixed shift value for entire alphabet
  • Easy to implement but very insecure
  • Vulnerable to frequency analysis and brute force
  • Important for understanding cryptographic principles
  • Led to development of more complex ciphers
Remember: Historical significance ≠ Modern security

Thank You

Questions & Discussion

Next: Columnar Transposition Cipher