Caesar Cipher
A basic substitution cipher where each letter is shifted by a fixed number in the alphabet.
ποΈ Historical Background of the Caesar Cipher
The Caesar Cipher is one of the oldest known encryption techniques, attributed to Julius Caesar. It is a substitution cipher where each letter in the plaintext is shifted by a fixed number of positions down or up the alphabet.
According to Roman historian Suetonius, Caesar would shift each letter in his messages by three positions to keep the content secret. Like, A
becomes D
, B
becomes E
, and so on.
This cipher was used by Julius Caesar to protect his private messages from being read by enemies. The simplicity of the cipher made it both fast and easy to use, but also easy to break without modern cryptographic techniques.
This simple technique was effective at the time because few people were literate and cryptographic awareness was low. It represents one of the earliest uses of substitution ciphers in history.
π Caesar Cipher Principle
The Caesar Cipher is a type of monoalphabetic substitution cipher where each letter in the plaintext is replaced with a letter a fixed number of positions away in the alphabet. By shifting each letter in a predictable way, the message becomes unreadable to someone who doesn't know the key. Without the shift value, the original meaning is hidden, even though the message still looks like regular letters.
For example, if we use a shift value of 3:
- A becomes D (A is moved 3 positions forward)
- B becomes E
- C becomes F
- and so onβ¦
The process is straightforward:
- Step 1: Choose a shift key (a number between 1 and 25).
- Step 2: Shift each letter in the plaintext by the number of positions indicated by the key.
- Step 3: Wrap around if the shift exceeds the letter "Z." For example, with a key of 3, X would become A, Y would become B, and Z would become C.
This method of encryption works by essentially "shifting" the alphabet. If you apply a shift of 3, the new alphabet would look like this:
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
Shifted Alphabet : 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
Key Characteristics:
-
Shift Value (Key): A number between 1 and 25, representing the fixed shift in the alphabet.
Key = 3: A β D, B β E, C β F
Key = 5: A β F, B β G, C β H
-
Alphabet Wrapping: If the shift goes past Z, it wraps back to A.
Key = 3 β X β A, Y β B, Z β C
Mathematical Representation:
Each letter is treated as a number:
A = 0, B = 1, C = 2, ..., Z = 25
π Encryption:
C = (P + K) mod 26
π Decryption:
P = (C - K + 26) mod 26
Where:
- C: Ciphertext letter (Result after encryption)
- P: Plaintext letter (Original text)
- K: Shift key (Number of Positions Shifted)
βοΈ Step-by-Step Guidance to Caesar Cipher
π Caesar Cipher Encryption
Step 1: Choose a Key (Shift Value)
The key determines how many positions each letter in the plaintext will shift in the alphabet. It can be any number between 1 and 25.
Example: Suppose the key is 3.
Step 2: Write Down the Plaintext
The plaintext is the original message you want to encrypt. This can include letters, spaces, and punctuation. Only alphabetic characters are shifted.
Example: Plaintext = HELLO WORLD
Step 3: Substitute Letters Using the Key
Key = 3 H β K (H = 7 β 7 + 3 = 10 β K) E β H (E = 4 β 4 + 3 = 7 β H) L β O (L = 11 β 11 + 3 = 14 β O) L β O (L = 11 β 11 + 3 = 14 β O) O β R (O = 14 β 14 + 3 = 17 β R) W β Z (W = 22 β 22 + 3 = 25 β Z) O β R (O = 14 β 14 + 3 = 17 β R) R β U (R = 17 β 17 + 3 = 20 β U) L β O (L = 11 β 11 + 3 = 14 β O) D β G (D = 3 β 3 + 3 = 6 β G) π Encrypted Text: KHOOR ZRUOG
π Caesar Cipher Decryption
Step 1: Use the Same Key
The decryption process uses the same key as encryption to reverse the shifts.
Example: Key = 3
Step 2: Write Down the Ciphertext
Example: Ciphertext = KHOOR ZRUOG
Step 3: Reverse the Shift for Each Letter
- Find Alphabet Position: A=0, B=1, ..., Z=25
- Subtract the Key: Example: K = 10 β 10β3 = 7 β H
- Handle Wraparound: If result is negative, add 26
Example: C = 2 β 2β5 = -3 β -3+26 = 23 β X - Find New Letter: Replace the letter with the one at the new position
Note: Non-alphabetic characters (spaces, punctuation) remain unchanged.
Key = 3 K β H (10 β 3 = 7 β H) H β E (7 β 3 = 4 β E) O β L (14 β 3 = 11 β L) O β L (14 β 3 = 11 β L) R β O (17 β 3 = 14 β O) Z β W (25 β 3 = 22 β W) R β O (17 β 3 = 14 β O) U β R (20 β 3 = 17 β R) O β L (14 β 3 = 11 β L) G β D (6 β 3 = 3 β D) π Decrypted Text: HELLO WORLD
Caesar Cipher Quiz
- The Caesar Cipher is a substitution cipher where each letter in the plaintext is shifted by a certain number.
- Example: A shift of 3 would change A to D, B to E, C to F, and so on.
Result:
Score: 0
π Additional Resources
- Caesar Cipher Tutorial (Part 2) - View Resource
- Caesar Cipher Encryption - View Resource