The Atbash Cipher: Reverse Alphabet Substitution

Learn about the Atbash cipher, which maps A to Z, B to Y, and so on. Understand how it relates to the Caesar cipher and its historical use in Hebrew biblical texts.

Variants

Detailed Explanation

The Atbash Cipher

The Atbash cipher is a substitution cipher where the alphabet is reversed: A maps to Z, B maps to Y, C maps to X, and so on. It is one of the oldest known ciphers, originating from Hebrew cryptography.

The Substitution Table

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

Relationship to Caesar Cipher

Atbash can be expressed as a formula:

Atbash(x) = 25 - x

This is NOT a simple shift. It's a reflection around the middle of the alphabet. However, it can be seen as related to the Caesar family:

  • Caesar: E(x) = (x + k) mod 26
  • Atbash: E(x) = (25 - x) mod 26

Atbash is an affine cipher with a = -1 and b = 25.

Self-Reciprocal Property

Like ROT13, Atbash is self-reciprocal:

Atbash('A') = 'Z'
Atbash('Z') = 'A'

Applying Atbash twice always returns the original:

Atbash(Atbash(x)) = 25 - (25 - x) = x

Historical Use

The name "Atbash" comes from Hebrew, where it was used in biblical texts:

  • Aleph (first letter) → Tav (last letter)
  • Bet (second letter) → Shin (second-to-last letter)

The prophet Jeremiah used Atbash in the Bible: "Sheshach" (in Jeremiah 25:26) is the Atbash cipher of "Babel" (Babylon) in Hebrew.

Implementation

function atbash(text) {
  return text.replace(/[a-zA-Z]/g, c => {
    const base = c <= 'Z' ? 65 : 97;
    return String.fromCharCode(base + 25 - (c.charCodeAt(0) - base));
  });
}

Example

"HELLO WORLD" → "SVOOL DLIOW"
"ATTACK AT DAWN" → "ZGGZXP ZG WZDM"

Comparison with ROT13

Feature ROT13 Atbash
Operation Shift by 13 Reverse alphabet
Self-reciprocal Yes Yes
A becomes N Z
Preserves case Yes Yes
Mathematical basis Addition mod 26 Reflection (25 - x)

Use Case

The Atbash cipher is studied in biblical scholarship, history of cryptography, and as an alternative substitution cipher example in programming courses. It demonstrates that substitution ciphers extend beyond simple shifts to include reflections and affine transformations.

Try It — ROT13 / Caesar Cipher

Open full tool