Skip to content

Added A1Z26 Cipher #1914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 29, 2020
29 changes: 29 additions & 0 deletions ciphers/a1z26.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Convert a string of characters to a sequence of numbers
corresponding to the character's position in the alphabet.

https://www.dcode.fr/letter-number-cipher
http://bestcodes.weebly.com/a1z26.html
"""

def encode(plain: str) -> list:
"""
>>> encode("myname")
[13, 25, 14, 1, 13, 5]
"""
return [ord(elem) - 96 for elem in plain]

def decode(encoded: list) -> str:
"""
>>> decode([13, 25, 14, 1, 13, 5])
'myname'
"""
return "".join(chr(elem + 96) for elem in encoded)

def main():
encoded = encode(input("->").strip().lower())
print("Encoded: ", encoded)
print("Decoded:", decode(encoded))

if __name__ == "__main__":
main()