Caesar Cipher
Nerd Cafe
The Caesar Cipher is one of the simplest and most widely known encryption techniques. It shifts each letter in the plaintext by a fixed number of places down the alphabet. Letβs go step by step:
Step 1: Understand the Concept
Encryption: Each letter in the plaintext is shifted by a fixed number (key). For example, with a shift of 3, A becomes D, B becomes E, and so on.
Decryption: Reverse the process by shifting letters back by the same key.
Step 2: Choose the Key
The key is the number of positions each letter is shifted. For instance, a key of 3 means each letter in the plaintext will move three steps forward.
Step 3: Define the Alphabet
The standard alphabet is used:
ABCDEFGHIJKLMNOPQRSTUVWXYZIf you encounter lowercase letters, treat them similarly:
abcdefghijklmnopqrstuvwxyzStep 4: Encryption Formula
Use the formula:
Where:
πΆπ: Ciphertext letter (encrypted letter)
ππ: Plaintext letter (original letter)
πΎ: Key (shift value)
26: Total letters in the English alphabet
Step 5: Decryption Formula
Reverse the encryption formula:
Step 6: Practical Example
Plaintext: "
HELLO"Key: 3
Step 6.1: Encryption
Take each letter and shift it by 3:
H β K
E β H
L β O
L β O
O β R
Ciphertext: "KHOOR"
Step 6.2: Decryption
Take each letter in the ciphertext and shift it back by 3:
K β H
H β E
O β L
O β L
R β O
Decrypted Text: "HELLO"
Step 7: Implementation in Python
Output
Notes
Non-alphabetic characters are typically not encrypted but can be handled based on specific requirements.
The Caesar Cipher is not secure for modern cryptography but is excellent for understanding the basics of encryption.
Last updated