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:
@@ -1,6 +1,6 @@
|
||||
## @file __init__.py
|
||||
# @brief Public API of the caesar_cipher package.
|
||||
|
||||
from caesar_cipher.cipher import encrypt
|
||||
from caesar_cipher.cipher import decrypt, encrypt
|
||||
|
||||
__all__ = ["encrypt"]
|
||||
__all__ = ["encrypt", "decrypt"]
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user