Python Message Encrypter
About This Project
The Python Message Encrypter is a project that demonstrates different encryption techniques used to secure messages. This is a great beginner project for learning about string manipulation, cryptography basics, and Python functions.
Encryption Methods
1. Caesar Cipher
Shifts each letter by a fixed number of positions in the alphabet. Named after Julius Caesar who used it for military communications.
2. ROT13
A special case of Caesar cipher with a fixed shift of 13. Since the alphabet has 26 letters, ROT13 is its own inverse.
3. Reverse Cipher
Simply reverses the entire message. A simple but effective method for basic obfuscation.
4. Base64 Encoding
Converts binary data to ASCII text. Not encryption, but commonly used to encode data for transmission.
Source Code
# Python Message Encrypter
# Demonstrates different encryption techniques
import base64
def caesar_cipher(text, shift):
result = ""
for char in text:
if char.isalpha():
ascii_offset = 65 if char.isupper() else 97
result += chr((ord(char) - ascii_offset + shift) % 26 + ascii_offset)
else:
result += char
return result
def rot13(text):
return caesar_cipher(text, 13)
def reverse_cipher(text):
return text[::-1]
def base64_encode(text):
return base64.b64encode(text.encode()).decode()
def base64_decode(text):
return base64.b64decode(text.encode()).decode()
def main():
print("Python Message Encrypter")
print("1. Caesar Cipher")
print("2. ROT13")
print("3. Reverse Cipher")
print("4. Base64 Encode")
print("5. Exit")
while True:
choice = input("\nSelect option: ")
if choice == '1':
text = input("Enter message: ")
shift = int(input("Enter shift (1-25): "))
print(f"Encrypted: {caesar_cipher(text, shift)}")
elif choice == '2':
text = input("Enter message: ")
print(f"Encrypted: {rot13(text)}")
print(f"Decrypted: {rot13(rot13(text))}")
elif choice == '3':
text = input("Enter message: ")
print(f"Encrypted: {reverse_cipher(text)}")
print(f"Decrypted: {reverse_cipher(reverse_cipher(text))}")
elif choice == '4':
text = input("Enter message: ")
encoded = base64_encode(text)
print(f"Encoded: {encoded}")
print(f"Decoded: {base64_decode(encoded)}")
elif choice == '5':
break
if __name__ == "__main__":
main()Example Output
Input: "Hello World"
Caesar (shift 3): "Khoor Zruog"
ROT13: "Uryyb Jbeyq"
Reverse: "dlroW olleH"
Base64: "SGVsbG8gV29ybGQ="
Learning Objectives
- Understand basic string manipulation in Python
- Learn about ASCII and character encoding
- Implement functions for encryption algorithms
- Work with the base64 module
- Handle user input and menu-driven programs