Skip to content

Commit 03a36b5

Browse files
committed
fix: add input validation to a1z26 encode()
1 parent c0db072 commit 03a36b5

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

ciphers/a1z26.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,19 @@ def encode(plain: str) -> list[int]:
1313
"""
1414
>>> encode("myname")
1515
[13, 25, 14, 1, 13, 5]
16+
>>> encode("")
17+
Traceback (most recent call last):
18+
...
19+
ValueError: input cannot be empty
20+
>>> encode("Hello")
21+
Traceback (most recent call last):
22+
...
23+
ValueError: input must contain only lowercase letters a-z
1624
"""
25+
if not plain:
26+
raise ValueError("input cannot be empty")
27+
if not plain.islower() or not plain.isalpha():
28+
raise ValueError("input must contain only lowercase letters a-z")
1729
return [ord(elem) - 96 for elem in plain]
1830

1931

0 commit comments

Comments
 (0)