Add decrypt function to Caesar cipher

- Implement decrypt function that reverses encryption with negative
  shift
- Export decrypt in package's public API
- Update tests with basic roundtrip and edge case tests
- Update documentation to reflect encryption/decryption support
This commit is contained in:
2026-10-04 13:18:33 +08:00
parent cdbf6396ab
commit 621f5f7272
5 changed files with 28 additions and 7 deletions
+9 -1
View File
@@ -1,5 +1,5 @@
## @file cipher.py
# @brief Caesar cipher encryption.
# @brief Caesar cipher encryption and decryption.
from caesar_cipher.constants import ALPHABET
@@ -19,3 +19,11 @@ def encrypt(text: str, shift: int) -> str:
else:
result.append(char)
return "".join(result)
def decrypt(text: str, shift: int) -> str:
## @brief Decrypt a Caesar-cipher text.
# @param text Encrypted text.
# @param shift Shift that was used to encrypt.
# @return The original text.
return encrypt(text, -shift)