Skip to content
39 changes: 39 additions & 0 deletions ciphers/a1z26.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""

Converts a string of characters to a sequence of numbers corresponding to the character's position in the alphabet.

Information URLs:
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]
"""
result = []
for elem in plain:
result.append(ord(elem) - 96)
return result
Comment thread
LethargicLeprechaun marked this conversation as resolved.
Outdated

def decode(encoded : list) -> str:
"""
>>> decode([13, 25, 14, 1, 13, 5])
'myname'
"""
result = ""
for elem in encoded:
result += chr(elem + 96)
return result
Comment thread
LethargicLeprechaun marked this conversation as resolved.
Outdated

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

if __name__ == "__main__":
main()