a1z26 Algorithm
The A1Z26 algorithm, also known as the A1Z26 cipher, is a simple and straightforward substitution cipher that replaces each letter in the plaintext with its corresponding number based on its position in the alphabet. This type of cipher is considered a monoalphabetic substitution cipher, where each letter in the plaintext is replaced by a fixed value based on a predetermined key. In the case of the A1Z26 cipher, the key is the natural ordering of the alphabet, where A is 1, B is 2, C is 3, and so on, up to Z which is 26. To encode a message, you simply convert each letter to its corresponding number and separate the numbers with a chosen delimiter, such as a space or a period.
Although the A1Z26 algorithm is easy to understand and implement, it offers a very low level of security, making it unsuitable for protecting sensitive information. The simplicity of the algorithm makes it vulnerable to frequency analysis and other basic cryptanalysis techniques. In essence, the A1Z26 cipher is more suitable as a puzzle or an introduction to cryptography rather than a practical encryption method. Despite its limitations, the A1Z26 cipher can still be a fun and engaging way to introduce people to the world of cryptography and help them develop an understanding of more complex encryption techniques.
"""
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()