From 03a36b5132768704eafc31cb5af34754ec20ebd7 Mon Sep 17 00:00:00 2001 From: mithunbabbira Date: Sun, 19 Jul 2026 19:55:24 +0530 Subject: [PATCH] fix: add input validation to a1z26 encode() --- ciphers/a1z26.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ciphers/a1z26.py b/ciphers/a1z26.py index a1377ea6d397..4c88d471a8c5 100644 --- a/ciphers/a1z26.py +++ b/ciphers/a1z26.py @@ -13,7 +13,19 @@ def encode(plain: str) -> list[int]: """ >>> encode("myname") [13, 25, 14, 1, 13, 5] + >>> encode("") + Traceback (most recent call last): + ... + ValueError: input cannot be empty + >>> encode("Hello") + Traceback (most recent call last): + ... + ValueError: input must contain only lowercase letters a-z """ + if not plain: + raise ValueError("input cannot be empty") + if not plain.islower() or not plain.isalpha(): + raise ValueError("input must contain only lowercase letters a-z") return [ord(elem) - 96 for elem in plain]