Skip to content

A command-line tool for text encryption and decryption supporting symmetric (AES, DES) and asymmetric (RSA) cryptographic algorithms.

License

Notifications You must be signed in to change notification settings

samad-pasha/Multi-Algorithm-Text-Encryptor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multi-Algorithm Text Encryption Tool

Python Version License: MIT Dependencies

A versatile, interactive command-line tool built in Python for encrypting and decrypting text using a variety of standard cryptographic algorithms. This tool serves as a practical demonstration of symmetric (AES, DES) and asymmetric (RSA) encryption within a single, easy-to-use interface.

Features

  • Multiple Algorithms: Supports three widely recognized encryption standards:
    • AES (Advanced Encryption Standard): A modern, secure symmetric algorithm.
    • DES (Data Encryption Standard): A legacy symmetric algorithm (specifically TripleDES).
    • RSA: A powerful asymmetric (public-key) algorithm.
  • Flexible Key Management:
    • Symmetric Keys (AES/DES):
      • Generate cryptographically secure random keys.
      • Derive fixed-length keys from any user-provided password or phrase using a SHA-256 hash function.
    • Asymmetric Keys (RSA):
      • Automatically generates a 2048-bit RSA public/private key pair for the duration of the session.
  • Interactive CLI: A user-friendly menu-driven interface guides you through the process of encryption and decryption.
  • In-Session Key Memory: The tool remembers the last-used AES/DES key and the session's RSA key pair, simplifying the process of encrypting and then immediately decrypting a message.

How It Works

This tool demonstrates two fundamental types of cryptography:

Symmetric Encryption (AES & DES)

In symmetric encryption, the same key is used for both encrypting and decrypting the data.

  1. Key Generation: You can either have the system generate a random binary key or provide your own password. The user-provided password is not used directly; instead, it's hashed using SHA-256 to produce a secure, fixed-length key suitable for the chosen algorithm (32 bytes for AES, 8 bytes for DES).
  2. Encryption: The plaintext is encrypted using the key and an initialization vector (IV) in CBC (Cipher Block Chaining) mode. The IV ensures that encrypting the same text multiple times produces different ciphertexts.
  3. Decryption: The ciphertext can only be decrypted back to the original plaintext using the exact same key that was used for encryption.

Asymmetric Encryption (RSA)

Asymmetric encryption uses a key pair: a public key and a private key.

  1. Key Generation: The first time you use RSA in a session, the tool generates a new public/private key pair.
  2. Encryption: Text is encrypted using the public key. The public key can be shared freely without compromising security.
  3. Decryption: The resulting ciphertext can only be decrypted using the corresponding private key. This private key must be kept secret. In this tool, the private key is held in memory for the session to allow for decryption.

Dependencies

  • Python 3.7+
  • cryptography library

Installation

  1. Clone the repository:

    git clone [https://github.com/your-username/Multi-Algorithm-Text-Encryptor.git](https://github.com/your-username/Multi-Algorithm-Text-Encryptor.git)
    cd Multi-Algorithm-Text-Encryptor
  2. Set up a virtual environment (recommended):

    python -m venv venv
    source venv/bin/activate  # On Windows, use: venv\Scripts\activate
  3. Install the required package:

    pip install -r requirements.txt

Usage

Run the script from your terminal:

python text_encryption.py

You will be presented with a menu. Follow the on-screen prompts to select an action (encrypt/decrypt) and an algorithm.

Example: AES Encryption and Decryption

Text Encryption System
1. Encrypt
2. Decrypt
3. Exit
Select an option (1-3): 1

Encryption Algorithms
1. AES Encryption
2. DES Encryption
3. RSA Encryption
Select an algorithm (1-3): 1
Enter text to encrypt: This is a secret message.
Use system-generated key? (y/n): n
Enter your key (any length or type): mySuperSecretPassword
Derived AES Key (base64): GSc+u4vCft2E7t4p17yR1g6pGLs/j7PZl3PEYRk3SGE=
Encrypted: fT4i2jP5hG88jY3kLq9wR... (example output)

Text Encryption System
...
Select an option (1-3): 2

Decryption Algorithms
1. AES Decryption
...
Select an algorithm (1-3): 1
Enter ciphertext to decrypt (base64): fT4i2jP5hG88jY3kLq9wR...
Use the key from last AES encryption? (y/n): n
Enter your key (any length or type): mySuperSecretPassword
Derived AES Key (base64): GSc+u4vCft2E7t4p17yR1g6pGLs/j7PZl3PEYRk3SGE=
Decrypted: This is a secret message.

⚠️ Security Disclaimer

  • Educational Purpose: This tool is intended for educational purposes to demonstrate how different cryptographic algorithms work. It is not recommended for securing sensitive production data without further auditing and robust key management practices.
  • Key Management:
    • For AES/DES, if you use a derived key, you must remember the exact password to decrypt your data. Losing the password means the data is permanently lost.
    • The RSA key pair is ephemeral, meaning it only exists for the current session. You cannot decrypt a message in a new session, as the private key will be gone.
  • Algorithm Strength: TripleDES is a legacy algorithm and is considered much weaker than modern standards like AES-256. Use AES for any serious application.

Developer Notes

This repository includes a launch.json file in the .vscode directory for easy debugging in Visual Studio Code. You can use the "Python Debugger: Current File" configuration to run and debug the script.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A command-line tool for text encryption and decryption supporting symmetric (AES, DES) and asymmetric (RSA) cryptographic algorithms.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages