CipherSafe

CipherSafe: Encrypt & Decrypt Your Messages


    from email.mime.application import MIMEApplication
    import os
    import sys
    from cryptography.fernet import Fernet
    import smtplib
    from email.mime.text import MIMEText
    from email.mime.multipart import MIMEMultipart 

    # Check if required modules are installed
    required_modules = ['cryptography', 'smtplib', 'email']
    for module in required_modules:
        if module not in sys.modules:
            print(f"Module '{module}' is not installed. Please run 'pip install {module}' to install it.")
            sys.exit(1)

    def generate_key(key_file):
        """Generate a new encryption key and save it to a file."""
        key = Fernet.generate_key()
        with open(key_file, "wb") as key_file:
            key_file.write(key)
        return key

    def load_key(key_file):
        """Load an encryption key from a file."""
        try:
            with open(key_file, "rb") as key_file:
                return key_file.read()
        except FileNotFoundError:
            print(f"Encryption key file '{key_file}' not found.")
            return None

    def encrypt_message(message, key):
        """Encrypt a message using the provided key."""
        try:
            fernet = Fernet(key)
            return fernet.encrypt(message.encode())
        except Exception as e:
            print(f"Failed to encrypt message: {e}")
            return None
            

    from cryptography.fernet import Fernet

    # Your encrypted message
    encrypted_message = b"..."  # Replace with your encrypted message

    # Your key (it should be the same key that was used to encrypt the message)
    key = b"..."  # Replace with your key from 'encryption_key.txt'

    # Initialize the Fernet class
    cipher_suite = Fernet(key)

    # Decrypt the message
    decrypted_message = cipher_suite.decrypt(encrypted_message)

    print(decrypted_message.decode())
            

Instructions: