Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Using find() and index solution in Clear category for Atbash Cipher by H0r4c3
def atbash(plaintext: str) -> str:
alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
cypher = 'zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA'
new_text = ''
for item in plaintext:
if item not in alphabet:
new_text = new_text + item
else:
index = alphabet.find(item)
new_text = new_text + cypher[index]
return new_text
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. 3, 2021
Comments: