Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for Atbash Cipher by Hunteena
from string import ascii_lowercase, ascii_uppercase
def atbash(plaintext: str) -> str:
substitution_table = dict(zip(ascii_lowercase, reversed(ascii_lowercase)))
substitution_table.update(zip(ascii_uppercase, reversed(ascii_uppercase)))
answer = ''
for char in plaintext:
translation = substitution_table.get(char, char)
answer += translation
return answer
if __name__ == "__main__":
print("Example:\nplaintext: testing")
print(atbash("testing"))
# These "asserts" are used for self-checking and not for an auto-testing
assert atbash("testing") == "gvhgrmt"
assert atbash("attack at dawn") == "zggzxp zg wzdm"
assert atbash("Hello, world!") == "Svool, dliow!"
print("Coding complete? Click 'Check' to earn cool rewards!")
Jan. 18, 2022
Comments: