The Atbash Cipher

Mr. Robot
InfoSec Adventures
Published in
2 min readSep 26, 2018

The Atbash cipher is another type of substitution cipher. It entails replacing each letter in the plaintext with the corresponding letter if the alphabet were reversed.

The Atbash cipher does not use a key and this is the reason why it doesn’t provide any communication security. The idea here is simple, just reverse the alphabet and substitute the letters. A becomes Z, B becomes Y, and so on… I think there is not much to explain the example is pretty straightforward.

Encrypted message:

HVXIVG

Decrypted message:

SECRET

Source Code

If you’re not a programmer or new to programming, don’t worry I try to explain how the code works.

The encrypt(message) method.

First, I removed the usual special characters. Next, the loops go through the message character by character. If the current character is not in the alphabet, then simply append the character to the encrypted message and move on. I got the shifted index by subtracting the index of the character from the length of the alphabet. Finally, I appended the letter at the shifted index to the encrypted message variable.

The decrpyt(message) method.

Obviously, the decrypt(message) method is exactly the same as the encrypt(message) method.

The Full Source Code

I created a gist on Github, so you can download and try the whole program.

Atbash cipher implemented in Python.

Feel free to download and experiment with the code!

Before you go

Thank you for taking the time to read my article. If you found it helpful, please hit the 👏 button 👏 (up to 50x) and share it to help others with similar interest find it! + Feedback is always welcome! 🙏

--

--

Mr. Robot
InfoSec Adventures

Self-taught developer with an interest in Offensive Security. I regularly play on Vulnhub and Hack The Box.