Today I realized Atbash can done as an algorithm, rather than looking up a hard-coded dictionary of an alphabet to its reversed alphabet. You could encrypt using the alphabet’s array index as: -i +25
It’s that simple.
cipherCharacter = alphabet[ -alphabet.index(i) + 25 ]
Assuming you have a list of an alphabet, index(i) will get the plaintext chacter’s position. Then negate it and add 25, and now you have the index position of the Atbash character. Slick!
import string text = "No more rhymes now I mean it" print(text) alphabet = list(string.ascii_uppercase) result = '' for i in list(text.upper()): if i in alphabet: result += alphabet[ -alphabet.index(i) + 25 ] else: result += i print(result)
No more rhymes now, I mean it. ML NLIV ISBNVH MLD, R NVZM RG.