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
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

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

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

if __name__ == "__main__":
main()