Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
translate solution in Clear category for Atbash Cipher by marcopunteri
from string import ascii_lowercase as lcase, ascii_uppercase as ucase
def atbash(plaintext: str) -> str:
translation_table = dict(zip(lcase+ucase,lcase[::-1]+ucase[::-1]))
return plaintext.translate(plaintext.maketrans(translation_table))
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!")
Dec. 2, 2021