Atbash Cipher
Introduction
The Atbash cipher is a substitution cipher originally applied to the Hebrew alphabet. Its name derives from the Hebrew names of some letters. Its cipher alphabet is as follows,
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 |
In simple terms, the cipher alphabet is the reverse of the plain alphabet.
Programming Atbash
If you were writing an algorithm to implement Atbash as your first cipher, you would probably look at the mathematical relationship between the positions of letters in the plain and cipher alphabets. If you number the letter positions of the plain alphabet from 0 to 25, then the letter you substitute is always 25 minus the position of the current letter. A is position 0 and is replaced with Z at position 25 (25 - 0 = 25). B is position 1 and is replaced with Y at position 24 (25 - 1 = 24).
We can also use the arbitrary letter substitution pseudocode if we replace the cipher alphabet with the Atbash cipher alphabet,
cipherAlphabet ← "ZYXWVUTSRQPONMLKJIHGFEDCBA"
plain ← "The secret is out."
upper ← UPPERCASE(plain)
cipherText ← ""
FOR letter ← 0 TO upper.LENGTH - 1
tmpASC ← ASCII CODE OF upper[letter]
IF tmpASC > = 65 AND tmpASC <= 90 THEN
cipherText ← cipherText + cipherAlphabet[tmpASC-65]
ELSE
cipherText ← cipherText + upper[letter]
END IF
END FOR
OUTPUT cipherText
Challenges
One obvious challenge is to implement both algorithms for Atbash.
As with ROT-13, Atbash throws up a few quirky situations where encrypted words make other words. This approach is claimed to be used in a few places in ancient religious texts. You can use word lists and dictionaries to uncover some of these for yourself. Here are a few,
ALL | ZOO |
ARK | ZIP |
ART | ZIG |
GILT | TROG |
GIRL | TRIO |
GLOW | TOLD |
GROG | TILT |
HOB | SLY |
HOLD | SLOW |
HOLY | SLOB |
HORN | SLIM |
ILL | ROO |
IRK | RIP |
OLD | LOW |