Skip to content

Commit c9b24c7

Browse files
Merge pull request steam-bell-92#1333 from Siddh2024/fix/1293-caesar-cipher-input-validation
[BUG] Caesar cipher script has no input validation - crashes on non-alphabetic input
2 parents b8d153d + 5d0c300 commit c9b24c7

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

utilities/Caesar-Cipher/Caesar-Cipher.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,23 @@ def main() -> None:
3737

3838
elif choice in ["E", "ENCRYPT", "D", "DECRYPT"]:
3939
message = input("📝 Enter your message: ")
40-
40+
41+
if not message.strip():
42+
print("❌ Error: Message cannot be empty.\n")
43+
continue
44+
45+
non_alpha = sum(1 for c in message if not (c.isascii() and c.isalpha()))
46+
if non_alpha > 0:
47+
print(f"⚠️ Warning: {non_alpha} non-alphabetic character(s) will be left unchanged.\n")
48+
4149
try:
4250
shift = int(input("🔑 Enter the shift key (whole number): "))
4351
except ValueError:
4452
print("❌ Error: Shift key must be a valid whole number.\n")
4553
continue
46-
54+
4755
result = caesar_cipher(message, shift, choice)
48-
56+
4957
print("\n✨ Resulting Message:")
5058
print(f"👉 {result}\n")
5159

0 commit comments

Comments
 (0)