From 3e23055eb6b78619788c0241829f90a08a6702e8 Mon Sep 17 00:00:00 2001 From: Ali Satwat Khan Date: Tue, 14 Jul 2026 23:34:57 +0500 Subject: [PATCH 1/2] fix: raise ValueError in encode() for non-lowercase input encode() previously accepted uppercase letters, digits, and other non-lowercase characters silently, producing incorrect/out-of-range values (e.g. negative numbers for uppercase letters) instead of failing. Add input validation using str.islower() and str.isalpha() to raise a ValueError when the input isn't purely lowercase a-z. Added a doctest covering the new error case. --- ciphers/a1z26.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ciphers/a1z26.py b/ciphers/a1z26.py index a1377ea6d397..4fc7aa9c2f25 100644 --- a/ciphers/a1z26.py +++ b/ciphers/a1z26.py @@ -13,7 +13,11 @@ def encode(plain: str) -> list[int]: """ >>> encode("myname") [13, 25, 14, 1, 13, 5] + >>> encode("ABCD") + ValueError: plain must contain only lowercase letters (a-z) """ + if not plain.islower() or not plain.isalpha(): + raise ValueError("plain must contain only lowercase letters (a-z)") return [ord(elem) - 96 for elem in plain] From 9ff2a0b8ee82876dec89bf2350bfa49080b675bd Mon Sep 17 00:00:00 2001 From: Ali Satwat Khan Date: Tue, 14 Jul 2026 23:58:55 +0500 Subject: [PATCH 2/2] resolved doctest --- ciphers/a1z26.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ciphers/a1z26.py b/ciphers/a1z26.py index 4fc7aa9c2f25..102cef4e424e 100644 --- a/ciphers/a1z26.py +++ b/ciphers/a1z26.py @@ -14,6 +14,8 @@ def encode(plain: str) -> list[int]: >>> encode("myname") [13, 25, 14, 1, 13, 5] >>> encode("ABCD") + Traceback (most recent call last): + ... ValueError: plain must contain only lowercase letters (a-z) """ if not plain.islower() or not plain.isalpha():