Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions ciphers/a1z26.py
Original file line numberDiff line numberDiff 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()