Skip to main content

A comprehensive encryption library for Python.

Project description

# EncryptionX

EncryptionX is a comprehensive encryption library for Python that provides a wide range of encryption and decryption functionalities. It covers various cryptographic techniques including base encoding, hashing, symmetric encryption, asymmetric encryption, and protocol-based encryption. The library is designed with a modular architecture and can handle inputs as text, file, or folder.

---

## Features

- **Base Encoding:**  
  - Base64, Base32, Base16 encoding and decoding.

- **Hashing:**  
  - MD5 and SHA256 hashing (one-way functions).

- **Symmetric Encryption:**  
  - **AES:** Advanced Encryption Standard with support for CBC and ECB modes.
  - **DES:** Data Encryption Standard (CBC and ECB modes).
  - **Triple DES:** Triple Data Encryption Standard (CBC and ECB modes).
  - **RC4:** Stream cipher implementation.

- **Asymmetric Encryption:**  
  - **RSA:** Public-key encryption with key generation, encryption, and decryption.

- **Protocol-based Encryption:**  
  - **PGP (Pretty Good Privacy):** Demonstrative implementation that combines symmetric (AES) and asymmetric (RSA) encryption for secure data exchange.

- **Utility Functions:**  
  - Functions for reading inputs (from text, file, or folder) and writing outputs.
  
- **Encode/Decode Classes:**  
  - High-level classes (`Encode` and `Decode`) that provide a unified interface for all encryption and decryption methods.

---

## Installation

### Prerequisites
- Python 3.6 or higher.
- [PyCryptodome](https://pycryptodome.readthedocs.io/) library.

### Using pip
Install the package (if published) via pip:
```bash
pip install encryptionx

Alternatively, if you have the source code, navigate to the project directory and run:

pip install .

Usage

Below are examples demonstrating how to use the various sections of EncryptionX.

Base Encoding

from encryptionx import Encode, Decode

# Create instances
encoder = Encode()
decoder = Decode()

# Example text
text = "This is a sample text for base encoding."

# Base64 Encoding/Decoding
encoded_b64 = encoder.base64(text, mode='text')
decoded_b64 = decoder.base64(encoded_b64, mode='text')
print("Base64 Encoded:", encoded_b64)
print("Base64 Decoded:", decoded_b64.decode('utf-8'))

# Similarly, you can use base32 and base16
encoded_b32 = encoder.base32(text, mode='text')
decoded_b32 = decoder.base32(encoded_b32, mode='text')
print("Base32 Encoded:", encoded_b32)
print("Base32 Decoded:", decoded_b32.decode('utf-8'))

encoded_b16 = encoder.base16(text, mode='text')
decoded_b16 = decoder.base16(encoded_b16, mode='text')
print("Base16 Encoded:", encoded_b16)
print("Base16 Decoded:", decoded_b16.decode('utf-8'))

Hashing

Hashing functions provide one-way encryption (cannot be decrypted).

# MD5 and SHA256 Hashing
hashed_md5 = encoder.md5("This is a text to hash", mode='text')
hashed_sha256 = encoder.sha256("This is a text to hash", mode='text')
print("MD5 Hash:", hashed_md5.decode('utf-8'))
print("SHA256 Hash:", hashed_sha256.decode('utf-8'))

Symmetric Encryption

AES Example

# Define a symmetric key (must be 16, 24, or 32 bytes)
symmetric_key = b'0123456789abcdef'
encoder = Encode(key=symmetric_key)
decoder = Decode(key=symmetric_key)

# AES encryption and decryption using CBC mode
aes_encrypted = encoder.aes("This is a secret message for AES encryption", mode='text', cipher_mode='CBC')
aes_decrypted = decoder.aes(aes_encrypted, mode='text', cipher_mode='CBC')
print("AES Encrypted:", aes_encrypted)
print("AES Decrypted:", aes_decrypted.decode('utf-8'))

DES Example

# DES key must be exactly 8 bytes long
des_key = b'12345678'
encoder = Encode(key=des_key)
decoder = Decode(key=des_key)

des_encrypted = encoder.des("This is a secret message for DES encryption", mode='text', cipher_mode='CBC')
des_decrypted = decoder.des(des_encrypted, mode='text', cipher_mode='CBC')
print("DES Encrypted:", des_encrypted)
print("DES Decrypted:", des_decrypted.decode('utf-8'))

Triple DES Example

# Triple DES key must be 16 or 24 bytes long
triple_des_key = b'0123456789abcdef01234567'
encoder = Encode(key=triple_des_key)
decoder = Decode(key=triple_des_key)

triple_des_encrypted = encoder.triple_des("This is a secret message for Triple DES encryption", mode='text', cipher_mode='CBC')
triple_des_decrypted = decoder.triple_des(triple_des_encrypted, mode='text', cipher_mode='CBC')
print("Triple DES Encrypted:", triple_des_encrypted)
print("Triple DES Decrypted:", triple_des_decrypted.decode('utf-8'))

RC4 Example

# RC4 can use any key length (commonly 16 bytes are used)
rc4_key = b'0123456789abcdef'
encoder = Encode(key=rc4_key)
decoder = Decode(key=rc4_key)

rc4_encrypted = encoder.rc4("This is a secret message for RC4 encryption", mode='text')
rc4_decrypted = decoder.rc4(rc4_encrypted, mode='text')
print("RC4 Encrypted:", rc4_encrypted)
print("RC4 Decrypted:", rc4_decrypted.decode('utf-8'))

Asymmetric Encryption (RSA)

from encryptionx import generate_rsa_keys

# Generate RSA keys
rsa_public, rsa_private = generate_rsa_keys()

# Create encoder and decoder with RSA keys
encoder = Encode(public_key=rsa_public)
decoder = Decode(private_key=rsa_private)

rsa_encrypted = encoder.rsa("This is a secret message for RSA encryption", mode='text')
rsa_decrypted = decoder.rsa(rsa_encrypted, mode='text')
print("RSA Encrypted:", rsa_encrypted)
print("RSA Decrypted:", rsa_decrypted.decode('utf-8'))

Protocol-based Encryption (PGP)

# PGP encryption combines symmetric and asymmetric encryption.
# It generates a random AES key for symmetric encryption and encrypts the AES key using RSA.
pgp_encrypted = encoder.pgp("This is a secret message for PGP encryption", mode='text')
pgp_decrypted = decoder.pgp(pgp_encrypted, mode='text')
print("PGP Encrypted:", pgp_encrypted)
print("PGP Decrypted:", pgp_decrypted.decode('utf-8'))

License

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


Author

Mohammad Taha Gorji


Acknowledgements

EncryptionX makes use of the PyCryptodome library for cryptographic functions. Special thanks to the contributors and the open-source community.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

encryptionx-2.0.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

encryptionx-2.0.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file encryptionx-2.0.0.tar.gz.

File metadata

  • Download URL: encryptionx-2.0.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.1

File hashes

Hashes for encryptionx-2.0.0.tar.gz
Algorithm Hash digest
SHA256 42367ae9c8eb92779eca1afeb0a1ba3986492532c2f193560d578691cf71bd38
MD5 ac075dfe91eedc9648290787dd0896e6
BLAKE2b-256 97deed2c8af80734a9a1cd91df9f0fd0e7b7c7d7e27e20592c16b5ff27f568ad

See more details on using hashes here.

File details

Details for the file encryptionx-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: encryptionx-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.1

File hashes

Hashes for encryptionx-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a632d9ceb4f81ce1bd17568a9b638487b3bf1a096aba6af0d35ee9776c49f225
MD5 3b83b1fe61b4bedc02394b21b31c0cd2
BLAKE2b-256 8e7c19fa6d691b2bd807bbfe2fa5db7ff8eb867c2721848eabb15b1226959adc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page