This project provides a simple, robust implementation of the Caesar cipher in Python. The Caesar cipher is a classic encryption technique that shifts each letter in the plaintext by a fixed number of positions in the alphabet.
- Encrypt and decrypt messages using a shift value
- Preserves case (uppercase/lowercase)
- Non-alphabetic characters are not changed
- Command-line interface for easy use
- Well-structured, type-annotated code
python caesar.py enc 3 "Meet me at 10"
python caesar.py dec 3 "Phhw ph dw 10"
enc
: Encrypt the messagedec
: Decrypt the message3
: The shift amount (can be any integer)- The text must be in quotes if it contains spaces
Encrypt:
python caesar.py enc 5 "Hello, World!"
# Output: Mjqqt, Btwqi!
Decrypt:
python caesar.py dec 5 "Mjqqt, Btwqi!"
# Output: Hello, World!
You can also import and use the cipher in your own Python code:
from caesar import caesar_cipher
encrypted = caesar_cipher("Secret Message", 4)
decrypted = caesar_cipher(encrypted, -4)
print(encrypted) # Output: Wigvix Qiwweki
print(decrypted) # Output: Secret Message
- Python 3.6 or higher
- No external dependencies
See LICENSE for details.