Add Caesar cipher project with Doxygen docs

This commit is contained in:
2026-10-04 13:11:15 +08:00
parent 99cccdf3da
commit 0957bff43a
12 changed files with 248 additions and 1 deletions
+21
View File
@@ -0,0 +1,21 @@
## @file cipher.py
# @brief Caesar cipher encryption.
from caesar_cipher.constants import ALPHABET
def encrypt(text: str, shift: int) -> str:
## @brief Encrypt a text with the Caesar cipher.
# @param text Original text.
# @param shift Positions to move each letter (may be negative or > 26).
# @return The encrypted text; non-letters are kept, case is preserved.
result = []
for char in text:
lower = char.lower()
if lower in ALPHABET:
new_position = (ALPHABET.index(lower) + shift) % len(ALPHABET)
new_char = ALPHABET[new_position]
result.append(new_char.upper() if char.isupper() else new_char)
else:
result.append(char)
return "".join(result)