Atbash Cipher Encoder & Decoder

Convert text using this ancient Hebrew substitution cipher that reverses the alphabet

Enter all characters in your alphabet. The Atbash cipher will map the first character to the last, the second to the second-to-last, and so on.

Copied!
Atbash Cipher Visualization English Alphabet

Character Mapping:

The Atbash cipher is a simple substitution cipher that originated in ancient Hebrew. It works by replacing each letter with its "mirror" letter in the alphabet - so 'A' becomes 'Z', 'B' becomes 'Y', and so on. The name derives from the first, last, second, and second-to-last letters of the Hebrew alphabet (Aleph-Tav-Beth-Shin).

What is the Atbash Cipher?

The Atbash cipher is one of the oldest known substitution ciphers, originally used for the Hebrew alphabet. It works by replacing each letter with its mirror image in the alphabet - the first letter becomes the last, the second becomes the second-to-last, and so on.

How Does the Atbash Cipher Work?

The mechanism of the Atbash cipher is very straightforward:

  1. Take an alphabet (traditionally Hebrew, but can be applied to any alphabet)
  2. Create a substitution alphabet by reversing the original alphabet
  3. Replace each letter in your message with the corresponding letter from the substitution alphabet

For the English alphabet, the mapping looks like this:

Plain:    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
Cipher:   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

For example, the word "HELLO" would be encrypted as "SVOOL":

  • H → S
  • E → V
  • L → O
  • L → O
  • O → L

Historical Significance

The Atbash cipher is one of the earliest encryption methods, dating back to biblical times. The name "Atbash" comes from the first Hebrew letters (Aleph-Tav-Beth-Shin) of the pattern. It appears in some ancient Hebrew texts, including biblical literature such as the Book of Jeremiah, where the word "Sheshach" is believed to be an Atbash cipher for "Babel" (Babylon).

Interesting Property

One interesting property of the Atbash cipher is that it's its own inverse. This means the same algorithm used for encryption is also used for decryption. If you apply the Atbash cipher twice to any text, you'll get back the original text.

Understanding the Atbash Cipher

Origins in Biblical Times

The Atbash cipher is believed to be among the oldest cipher systems in history, originating with the ancient Hebrew scholars. It is a simple form of substitution cipher and was used in the Hebrew Bible (Tanakh). The name "Atbash" is derived from the first, last, second, and second-to-last letters of the Hebrew alphabet: Aleph (א), Tav (ת), Beth (ב), and Shin (ש).

In the Book of Jeremiah, the term "Sheshach" (ששך) is thought to be an Atbash encryption of "Babel" (בבל), referring to Babylon. This is one of the earliest known examples of encryption in literature.

The Simple Mathematics Behind Atbash

Mathematically, the Atbash cipher is quite straightforward. For an alphabet with n letters, the substitution pattern can be expressed as:

Mathematical Representation

For a letter at position \(p\) in an alphabet of length \(n\), the encrypted letter position \(e\) is:

\(e = (n - 1) - p\)

For example, in the English alphabet (n=26):

  • 'A' is at position 0, so its encryption is at position (26-1-0) = 25, which is 'Z'
  • 'M' is at position 12, so its encryption is at position (26-1-12) = 13, which is 'N'

Applications in Different Alphabets

1. Hebrew Alphabet

The original Atbash cipher was used with the 22 letters of the Hebrew alphabet:

Plain א ב ג ד ה ו ז ח ט י כ
Cipher ת ש ר ק צ פ ע ס נ מ ל

2. Greek Alphabet

The Atbash concept can also be applied to the 24 letters of the Greek alphabet:

Plain Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ
Cipher Ω Ψ Χ Φ Υ Τ Σ Ρ Π Ο Ξ

3. English Alphabet

The most common modern application is with the 26 letters of the English alphabet:

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

Special Case: Self-Inverting Letters

An interesting property of the Atbash cipher is that some letters may map to themselves if they are positioned equally distant from both ends of the alphabet. This occurs only in alphabets with an odd number of letters.

For example, in an alphabet of 5 letters (A, B, C, D, E), the letter C would map to itself because it is in the middle position.

Plain A B C D E
Cipher E D C B A

In the standard 26-letter English alphabet, there are no self-inverting letters because 26 is an even number.

Cryptographic Weakness

The Atbash cipher is extremely weak by modern cryptographic standards. It has several inherent weaknesses:

  • No Key: There is no key involved, making it a fixed substitution pattern.
  • Frequency Analysis: It is highly vulnerable to frequency analysis. Common letters like 'E' will still appear frequently but as their corresponding cipher letters.
  • Limited Variations: For any given alphabet, there is only one possible Atbash cipher.
  • Self-Inverse: The same operation is used for both encryption and decryption, which simplifies cryptanalysis.

Modern Uses of Atbash

Despite its cryptographic weaknesses, the Atbash cipher continues to be used in modern contexts:

  • Educational Tool: It serves as an excellent introduction to cryptography for beginners and students.
  • Puzzles and Games: The cipher is often featured in puzzle games, mystery novels, and treasure hunts.
  • Symbolic Usage: In some contemporary Jewish mystical traditions, Atbash is used for religious or symbolic purposes rather than for secure communication.
  • Pop Culture: The cipher has appeared in various books, films, and TV shows, including Dan Brown's novels and various detective series.

JavaScript Implementation

function atbashCipher(text, alphabet) {
    let result = '';
    
    for (let i = 0; i < text.length; i++) {
        const char = text[i];
        const index = alphabet.indexOf(char);
        
        // If character is in the alphabet, replace it with its mirror
        if (index !== -1) {
            result += alphabet[alphabet.length - 1 - index];
        } else {
            // Keep characters that are not in the alphabet unchanged
            result += char;
        }
    }
    
    return result;
}

Python Implementation

def atbash_cipher(text, alphabet):
    result = ""
    
    for char in text:
        # Find the position of the character in the alphabet
        index = alphabet.find(char)
        
        # If the character is in the alphabet, replace it with its mirror
        if index != -1:
            result += alphabet[len(alphabet) - 1 - index]
        else:
            # Keep characters that are not in the alphabet unchanged
            result += char
    
    return result

Security Warning

The Atbash cipher provides virtually no security in the modern world and should never be used for protecting sensitive information. It is included here primarily for educational and historical interest. For secure encryption, use established modern algorithms like AES, RSA, or ECC.

Conclusion

The Atbash cipher represents one of humanity's earliest attempts at cryptography. While it offers no practical security today, its historical significance and simplicity make it a fascinating part of cryptographic history. Its appearance in ancient religious texts demonstrates that the desire to hide or protect information has been with us for millennia. The cipher's simplicity also makes it an excellent starting point for anyone interested in learning about the fundamental concepts of substitution ciphers and encryption.