The Atbash Cipher is a substitution cipher that replaces each letter of the alphabet with its reverse counterpart. For example, in the English alphabet, 'A' is replaced with 'Z', 'B' with 'Y', and so on.
Let's go through the steps to encrypt and decrypt a message using the Atbash Cipher with a practical example.
Step-by-Step Explanation
Step 1: Understand the Atbash Cipher Rule
Write down the English alphabet:
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
Reverse: Z Y X W V U T S R Q P O N M L K J I H G F E D C B A
Each letter in the message is replaced by its counterpart in the reverse alphabet.
Step 2: Encrypt a Message
Suppose we want to encrypt the message: HELLO.
For each letter in "HELLO", find its reverse counterpart:
H → S
E → V
L → O
L → O
O → L
Replace the letters to get the ciphertext: SVOOL.
Step 3: Decrypt a Message
Decrypting is the same as encrypting because the Atbash Cipher is symmetric:
For each letter in "SVOOL", find its reverse counterpart:
S → H
V → E
O → L
O → L
L → O
Replace the letters to get the original plaintext: HELLO.
Practical Python Implementation
Here’s how you can implement the Atbash Cipher in Python:
def atbash_cipher(text):
# Define the alphabet
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
reverse_alphabet = alphabet[::-1] # Reverse the alphabet
# Create a mapping for the cipher
atbash_mapping = {alphabet[i]: reverse_alphabet[i] for i in range(len(alphabet))}
# Encrypt/Decrypt the text
result = ''
for char in text.upper(): # Convert to uppercase
if char in atbash_mapping:
result += atbash_mapping[char]
else:
result += char # Keep non-alphabet characters unchanged
return result
# Example Usage
plaintext = "HELLO"
ciphertext = atbash_cipher(plaintext)
print("Ciphertext:", ciphertext) # Output: SVOOL
# Decrypting is the same process
decrypted_text = atbash_cipher(ciphertext)
print("Decrypted Text:", decrypted_text) # Output: HELLO