- Notifications
You must be signed in to change notification settings - Fork 46.7k
/
Copy patha1z26.py
35 lines (25 loc) · 742 Bytes
/
a1z26.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
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
"""
from __future__ importannotations
defencode(plain: str) ->list[int]:
"""
>>> encode("myname")
[13, 25, 14, 1, 13, 5]
"""
return [ord(elem) -96foreleminplain]
defdecode(encoded: list[int]) ->str:
"""
>>> decode([13, 25, 14, 1, 13, 5])
'myname'
"""
return"".join(chr(elem+96) foreleminencoded)
defmain() ->None:
encoded=encode(input("-> ").strip().lower())
print("Encoded: ", encoded)
print("Decoded:", decode(encoded))
if__name__=="__main__":
main()