2020-04-29 22:23:51 +00:00
|
|
|
"""
|
|
|
|
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
|
|
|
|
"""
|
|
|
|
|
2020-04-30 20:47:11 +00:00
|
|
|
|
2021-03-22 06:59:51 +00:00
|
|
|
def encode(plain: str) -> list[int]:
|
2020-04-29 22:23:51 +00:00
|
|
|
"""
|
|
|
|
>>> encode("myname")
|
|
|
|
[13, 25, 14, 1, 13, 5]
|
|
|
|
"""
|
|
|
|
return [ord(elem) - 96 for elem in plain]
|
|
|
|
|
2020-04-30 20:47:11 +00:00
|
|
|
|
2021-03-22 06:59:51 +00:00
|
|
|
def decode(encoded: list[int]) -> str:
|
2020-04-29 22:23:51 +00:00
|
|
|
"""
|
|
|
|
>>> decode([13, 25, 14, 1, 13, 5])
|
|
|
|
'myname'
|
|
|
|
"""
|
|
|
|
return "".join(chr(elem + 96) for elem in encoded)
|
|
|
|
|
2020-04-30 20:47:11 +00:00
|
|
|
|
2021-03-22 06:59:51 +00:00
|
|
|
def main() -> None:
|
|
|
|
encoded = encode(input("-> ").strip().lower())
|
2020-04-29 22:23:51 +00:00
|
|
|
print("Encoded: ", encoded)
|
|
|
|
print("Decoded:", decode(encoded))
|
|
|
|
|
2020-04-30 20:47:11 +00:00
|
|
|
|
2020-04-29 22:23:51 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|