Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ciphers/a1z26.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,33 @@

from __future__ import annotations

import string


def encode(plain: str) -> list[int]:
"""
>>> encode("myname")
[13, 25, 14, 1, 13, 5]

>>> encode("")
Traceback (most recent call last):
...
ValueError: Input must contain only lowercase letters a-z.

>>> encode("HELLO")
Traceback (most recent call last):
...
ValueError: Input must contain only lowercase letters a-z.

>>> encode("hi there")
Traceback (most recent call last):
...
ValueError: Input must contain only lowercase letters a-z.
"""

if not plain or any(ch not in string.ascii_lowercase for ch in plain):
raise ValueError("Input must contain only lowercase letters a-z.")

return [ord(elem) - 96 for elem in plain]


Expand Down
Loading