Skip to main content
# 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.

Metadata

Release files for encryptionx 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for encryptionx 2.0.0
File Size Uploaded Provenance
encryptionx-2.0.0.tar.gz 9.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for encryptionx 2.0.0
File Interpreter ABI Platform
encryptionx-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.8 kB

Release files / encryptionx-2.0.0.tar.gz

Download URL encryptionx-2.0.0.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
42367ae9c8eb92779eca1afeb0a1ba3986492532c2f193560d578691cf71bd38
BLAKE2b-256 checksum
How to use checksums
97deed2c8af80734a9a1cd91df9f0fd0e7b7c7d7e27e20592c16b5ff27f568ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.1

Release files / encryptionx-2.0.0-py3-none-any.whl

Download URL encryptionx-2.0.0-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a632d9ceb4f81ce1bd17568a9b638487b3bf1a096aba6af0d35ee9776c49f225
BLAKE2b-256 checksum
How to use checksums
8e7c19fa6d691b2bd807bbfe2fa5db7ff8eb867c2721848eabb15b1226959adc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.1

Security for encryptionx 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page