- Overview
- Ciphers
- Atbash Cipher
- Examples
Atbash Cipher Examples - Learn Atbash Cipher with Interactive Code Tutorials
Learn how the Atbash cipher works through interactive examples and hands-on exercises. Practice encoding and decoding messages with this ancient Hebrew substitution method, from basic letter-swapping to real-world cryptanalysis challenges.
Interactive Atbash Cipher Examples
Learn Atbash through step-by-step examples from beginner to advanced level.
Simple Word - HELLO
BeginnerH→S, E→V, L→O, L→O, O→L. Each letter maps to its mirror position in the alphabet.
Common Word - WORLD
BeginnerW→D, O→L, R→I, L→O, D→W. The transformation is consistent and reversible.
The Word ATBASH
BeginnerA→Z, T→G, B→Y, A→Z, S→H, H→S. The cipher's own name demonstrates the mirror rule.
Short Sentence
IntermediateA sentence example showing that spaces are preserved while letters are mirrored.
Mixed Case Text
IntermediateAtbash preserves case while transforming letters.
Complex Message
AdvancedA full sentence with punctuation showing practical message encoding.
Hebrew Atbash Cipher Examples
Historical Hebrew Atbash examples from biblical texts.
Jeremiah 25:26 - Sheshach
Jeremiah 25:26The best-known biblical example where Sheshach encodes Babel, referring to Babylon.
Jeremiah 51:1 - Leb Kamai
Jeremiah 51:1Leb Kamai decodes to Kasdim, the Hebrew name for the Chaldeans.
Hebrew Alphabet Principle
Hebrew AlphabetThe name Atbash comes from pairing the first and last, then second and second-to-last Hebrew letters.
Atbash Cipher Programming Implementations
Production-ready examples in Python and JavaScript with detailed notes.
Python Implementation
def atbash_cipher(text):
"""
Encode/decode text using Atbash cipher
"""
result = ""
for char in text:
if char.isalpha():
# Handle uppercase letters
if char.isupper():
# A=0, Z=25, so Z-A = 25-0 = 25
position = ord(char) - ord('A')
new_position = 25 - position
result += chr(ord('A') + new_position)
# Handle lowercase letters
else:
position = ord(char) - ord('a')
new_position = 25 - position
result += chr(ord('a') + new_position)
else:
# Keep non-alphabetic characters as-is
result += char
return result
# Example usage
original = "HELLO WORLD"
encoded = atbash_cipher(original)
decoded = atbash_cipher(encoded) # Atbash is self-inverse
print(f"Original: {original}")
print(f"Encoded: {encoded}")
print(f"Decoded: {decoded}")A complete Python implementation that supports uppercase and lowercase letters and demonstrates Atbash's self-inverse behavior.
JavaScript Implementation
function atbashCipher(text) {
/**
* Encode/decode text using Atbash cipher
* @param {string} text - Input text to transform
* @returns {string} - Transformed text
*/
return text
.split('')
.map(char => {
if (/[A-Z]/.test(char)) {
// Handle uppercase letters (A=65, Z=90)
const position = char.charCodeAt(0) - 65;
const newPosition = 25 - position;
return String.fromCharCode(65 + newPosition);
} else if (/[a-z]/.test(char)) {
// Handle lowercase letters (a=97, z=122)
const position = char.charCodeAt(0) - 97;
const newPosition = 25 - position;
return String.fromCharCode(97 + newPosition);
}
// Keep non-alphabetic characters unchanged
return char;
})
.join('');
}
// Example usage with arrow function syntax
const encode = text => atbashCipher(text);
const decode = text => atbashCipher(text); // Same function!
// Test the implementation
const message = "Attack at Dawn";
const encoded = encode(message);
const decoded = decode(encoded);
console.log(`Original: ${message}`);
console.log(`Encoded: ${encoded}`);
console.log(`Decoded: ${decoded}`);A modern JavaScript implementation using ES6 features and a functional approach.
Advanced Python with Unicode
import string
from typing import Dict, Optional
class AtbashCipher:
"""
Advanced Atbash cipher implementation with multiple character sets
"""
def __init__(self, include_numbers: bool = False, include_special: bool = False):
self.include_numbers = include_numbers
self.include_special = include_special
self._create_mappings()
def _create_mappings(self) -> None:
"""Create character mapping dictionaries"""
self.mappings: Dict[str, str] = {}
# Letters
upper = string.ascii_uppercase
lower = string.ascii_lowercase
self.mappings.update({
char: upper[25 - i] for i, char in enumerate(upper)
})
self.mappings.update({
char: lower[25 - i] for i, char in enumerate(lower)
})
# Numbers (optional)
if self.include_numbers:
digits = string.digits
self.mappings.update({
char: digits[9 - i] for i, char in enumerate(digits)
})
# Special characters (optional)
if self.include_special:
special = '!@#$%^&*()_+-=[]{}|;':",./<>?'
reversed_special = special[::-1]
self.mappings.update({
char: reversed_special[i] for i, char in enumerate(special)
})
def transform(self, text: str) -> str:
"""Transform text using Atbash cipher"""
return ''.join(
self.mappings.get(char, char) for char in text
)
def encode(self, text: str) -> str:
"""Encode text (alias for transform)"""
return self.transform(text)
def decode(self, text: str) -> str:
"""Decode text (alias for transform - Atbash is self-inverse)"""
return self.transform(text)
# Usage examples
cipher = AtbashCipher()
advanced_cipher = AtbashCipher(include_numbers=True, include_special=True)
text = "Hello, World! 123"
print(f"Original: {text}")
print(f"Basic: {cipher.encode(text)}")
print(f"Advanced: {advanced_cipher.encode(text)}")A production-ready Python class with optional support for numbers and special characters.
Learning Atbash Through Examples
The Atbash cipher is best understood through practical examples that demonstrate its principles and applications. This comprehensive tutorial provides examples ranging from simple words to complex implementations.
Basic Examples
Simple Word Transformations
HELLO → SVOOL
- H (8th letter) → S (19th letter)
- E (5th letter) → V (22nd letter)
- L (12th letter) → O (15th letter)
- L (12th letter) → O (15th letter)
- O (15th letter) → L (12th letter)
WORLD → DLIOW The transformation demonstrates the consistent mirror mapping where each letter's position is subtracted from 26 (in a 1-based system) or 25 (in a 0-based system).
Progressive Difficulty Levels
Beginner Level
- Single words: ATBASH → ZGYZHS
- Simple phrases: MEET AT DAWN → NVVG ZG WZDA
- Mixed case preservation: Attack → Zggzxp
Intermediate Level
- Complete sentences with punctuation
- Numbers and special characters (when enabled)
- Real-world message examples
Advanced Level
- Paragraph-length texts
- Mixed content types
- Historical document analysis
Hebrew Examples and Biblical References
The Name "Atbash"
The cipher gets its name from the Hebrew alphabet pairing:
- Aleph (א) + Tav (ת) = AT
- Beth (ב) + Shin (ש) = BASH
Jeremiah 25 - Sheshach
Original Hebrew: ששך (Sheshach)
Atbash Decoded: בבל (Babel/Babylon)
This is the most famous biblical example where the prophet Jeremiah uses Atbash to encode the name of Babylon, possibly to avoid directly naming the powerful empire.
Jeremiah 51 - Leb Kamai
Original Hebrew: לב קמי (Leb Kamai)
Atbash Decoded: כשדים (Kasdim/Chaldeans)
Another example from Jeremiah where "Leb Kamai" (literally "heart of those who rise up against me") encodes "Kasdim" (Chaldeans).
Programming Implementations
Python Implementation
def atbash_cipher(text):
"""
Encode/decode text using Atbash cipher
"""
result = ""
for char in text:
if char.isalpha():
if char.isupper():
# A=0, Z=25, so Z-A = 25-0 = 25
position = ord(char) - ord('A')
new_position = 25 - position
result += chr(ord('A') + new_position)
else:
position = ord(char) - ord('a')
new_position = 25 - position
result += chr(ord('a') + new_position)
else:
result += char
return result
# Example usage
message = "The secret is hidden"
encoded = atbash_cipher(message)
decoded = atbash_cipher(encoded) # Atbash is self-inverse
print(f"Original: {message}")
print(f"Encoded: {encoded}")
print(f"Decoded: {decoded}")
JavaScript Implementation
function atbashCipher(text) {
return text
.split('')
.map(char => {
if (/[A-Z]/.test(char)) {
const position = char.charCodeAt(0) - 65;
const newPosition = 25 - position;
return String.fromCharCode(65 + newPosition);
} else if (/[a-z]/.test(char)) {
const position = char.charCodeAt(0) - 97;
const newPosition = 25 - position;
return String.fromCharCode(97 + newPosition);
}
return char;
})
.join('');
}
// Example usage
const message = "Attack at Dawn";
const encoded = atbashCipher(message);
const decoded = atbashCipher(encoded);
console.log(`Original: ${message}`);
console.log(`Encoded: ${encoded}`);
console.log(`Decoded: ${decoded}`);
Advanced Python Class
import string
from typing import Dict
class AtbashCipher:
def __init__(self, include_numbers=False, include_special=False):
self.include_numbers = include_numbers
self.include_special = include_special
self._create_mappings()
def _create_mappings(self):
self.mappings = {}
# Letters
upper = string.ascii_uppercase
lower = string.ascii_lowercase
self.mappings.update({
char: upper[25 - i] for i, char in enumerate(upper)
})
self.mappings.update({
char: lower[25 - i] for i, char in enumerate(lower)
})
# Numbers (optional)
if self.include_numbers:
digits = string.digits
self.mappings.update({
char: digits[9 - i] for i, char in enumerate(digits)
})
def transform(self, text):
return ''.join(
self.mappings.get(char, char) for char in text
)
Mathematical Foundation
The Atbash transformation can be expressed mathematically:
For a letter at position i (0-based indexing):
encoded_position = (alphabet_length - 1) - i
For English alphabet (26 letters):
encoded_position = 25 - i
This formula works for any alphabet length, making it adaptable to different languages.
Educational Applications
Classroom Activities
- Letter Mapping Exercises: Students create their own alphabet transformation charts
- Historical Analysis: Examining biblical texts for cipher patterns
- Programming Challenges: Implementing the cipher in different languages
- Cryptanalysis Practice: Learning to detect and break simple ciphers
Research Projects
- Analyzing frequency patterns in Atbash-encoded texts
- Comparing Atbash with other substitution ciphers
- Historical significance of biblical cryptography
- Development of cipher detection algorithms
Practical Exercises
Exercise 1: Basic Encoding
Encode these words using Atbash:
- SECRET
- CIPHER
- ANCIENT
Exercise 2: Hebrew Examples
Research and analyze these biblical references:
- Jeremiah 25 (Sheshach)
- Jeremiah 51 (Leb Kamai)
- Jeremiah 51 (Sheshach variant)
Exercise 3: Implementation Challenge
Write a program that:
- Accepts user input
- Applies Atbash transformation
- Detects if input is already Atbash-encoded
- Provides confidence scoring
Historical Significance
The Atbash cipher represents one of humanity's earliest encryption methods, demonstrating that the need for secure communication has existed for millennia. Its appearance in biblical texts shows that cryptography was not merely a military tool but also had religious and literary applications.
Modern Relevance
While not secure by modern standards, Atbash remains valuable for:
- Educational purposes in cryptography courses
- Puzzle and game development
- Historical text analysis
- Understanding the evolution of encryption methods
The simplicity of Atbash makes it an excellent introduction to cryptographic concepts, serving as a stepping stone to more complex ciphers and modern encryption algorithms.