Ciphers · Classical ciphers
The Atbash cipher
A for Z, B for Y. A keyless cipher from the Hebrew Bible that undoes itself.
Atbash is what you get by writing the alphabet backwards, so A becomes Z, B becomes Y, C becomes X, and so on to the end. It comes from the Hebrew Bible, it needs no key, and it undoes itself, so the same step encrypts and decrypts. WIZARD becomes DRAZIW.
Try it
Nothing you type here leaves your browser.
There's nothing to set. Paste the output back in and the original text returns.
How it works
Number the letters 0 to 25. The letter at position x is replaced by the letter at position 25 − x, so A (0) becomes Z (25) and N (13) becomes M (12). The first and last letters swap, the second and second-to-last swap, and the alphabet folds in the middle between M and N.
The mapping is a set of 13 swaps, so applying it twice puts every letter back where it started, the same property ROT13 has. Here's a small curiosity. In WIZARD the pairs W/D, I/R and Z/A are all Atbash partners, so Atbash of the word comes out as the word spelled backwards. Few words do that.
The name comes from the Hebrew alphabet, where the same idea reads "first letter for last, second for second-to-last": aleph and tav, bet and shin, giving A-T-B-Sh, "Atbash".
Where it turns up
Atbash is one of the oldest substitution ciphers on record, because it sits inside a sacred text. The Book of Jeremiah has a place name, Sheshach, in 25:26 and 51:41 that appears nowhere else in the Bible. Run the Hebrew letters of Bavel, Babylon (bet, bet, lamed), through Atbash and you get shin, shin, kaf, which is Sheshach. Many commentators therefore read the word as a coded way to write Babylon in passages critical of it. Another oddity in Jeremiah, Leb Kamai, gets the same reading as a disguised Kasdim, the Chaldeans. Scholars disagree about how far the practice goes.
It reached modern readers through fiction. In The Da Vinci Code the hero reads an Atbash-encoded word to recover the name Sofia from Baphomet, and puzzle designers have used it since, because it's simple enough to explain in a sentence.
Breaking it takes seconds
There's no key, so there's nothing to search for. If you suspect a text is Atbash, apply it and see whether English comes out. The letter counts give the method away too. English has E as its most common letter, and Atbash sends E to V, T to G, A to Z, O to L, I to R and N to M. In a 364-letter test paragraph encrypted with Atbash, the six commonest ciphertext letters are V (52 times), G (33), L (28), Z (28), I (27) and M (25). Those are E, T, O, A, R and N in disguise, in almost exactly the order of English. V at the top of the count, followed by G, is a giveaway.
The same holds for every monoalphabetic substitution cipher. One plaintext letter always becomes one ciphertext letter, so the shape of the language survives. Atbash is simply the case where the substitution is fixed and public.
A special case of the affine cipher
The affine cipher encrypts each letter x as ax + b modulo 26. Choose a = 25 and b = 25. Since 25 ≡ −1 (mod 26), the formula is −x + 25, which is Atbash. The Caesar cipher is the affine cipher with a = 1. So Atbash, Caesar and ROT13 all live in one family of 312 keys, and none is any stronger than the others.
Reversing the alphabet is also how the Beaufort cipher differs from the Vigenère cipher. Beaufort is a Vigenère cipher applied to the Atbash of the message, with each key letter moved one place on.
The code
Atbash in six lines.
// Atbash: the first letter becomes the last, the second the second-to-last, and so on. It has no key.
function atbash(text) {
return text.replace(/[a-z]/gi, function (ch) {
var base = ch <= 'Z' ? 65 : 97;
return String.fromCharCode(base + 25 - (ch.charCodeAt(0) - base));
});
}Common questions
Is Atbash really Hebrew?
The name is: aleph (first), tav (last), bet (second), shin (second to last). The Hebrew alphabet has 22 letters, so the mirror pairs are aleph with tav, bet with shin, and so on. Run on the Latin alphabet of 26 letters it swaps A with Z and N with M.
Can I use Atbash on a message with numbers?
The numbers are left alone. Only letters are mirrored, so Meet at 9 becomes Nvvg zg 9.
How is Atbash different from ROT13?
Both are their own inverse and need no key. ROT13 shifts every letter by 13, while Atbash reverses the alphabet. ROT13 moves A to N, and Atbash moves A to Z. Atbash is a shift only in the sense that it's the affine cipher with a = 25.
What is the key space of Atbash?
One. There's nothing to choose, so there's nothing to search. You apply it and read the result. A cipher with a fixed alphabet is what the ancient writers called a mirror alphabet.
How would I recognize Atbash in a puzzle?
Look at the letter counts. In English the commonest letter is E, and Atbash sends E to V, so a text whose commonest letter is V, followed by G (for T), is a good suspect. Then apply Atbash and see whether English comes out.
On the timeline
- 6th century BC The Hebrew scriptures contain Atbash substitutions (Jeremiah 25:26 and 51:41), reversing the alphabet.