Skip to main content

Position-Dependent Encryption (PDE) library with authentication and padding

Project description

PDECrypto

Position-Dependent Encryption (PDE) library in Python.

Security Notice

This library is educational and custom encryption.
It is not a replacement for AES, ChaCha20, or other vetted cryptography.
For real-world security, always use standardized and audited algorithms like AES-GCM or ChaCha20-Poly1305.

Installation

Requires Python >= 3.7

Install for development

pip install -e .

Install from PyPI

pip install pdecrypto

Usage

from pdecrypto import encrypt, decrypt

key = b"supersecretkey1234567890"

# Encrypt a file
with open("example.png", "rb") as f:
    data = f.read()
ciphertext = encrypt(data, key)
with open("example.enc", "wb") as f:
    f.write(ciphertext)

# Decrypt
with open("example.enc", "rb") as f:
    encrypted_data = f.read()
plaintext = decrypt(encrypted_data, key)
with open("example_decrypted.png", "wb") as f:
    f.write(plaintext)

Features

  • Block-based encryption (16 bytes per block)
  • Position-dependent subkeys
  • Byte permutation per block
  • HMAC authentication
  • PKCS#7-style padding

Testing

Run automated tests using unittest:

python -m unittest pdecrypto.tests.test_automated

Or discover all tests in the tests folder:

python -m unittest discover -s pdecrypto/tests

Documentation

Each function in the library has docstrings describing:

  • Purpose
  • Arguments
  • Return values
  • Exceptions

Example:

def encrypt(plaintext: bytes, key: bytes) -> bytes:
    """
    Encrypt a plaintext message using PDE.

    Args:
        plaintext (bytes): Message to encrypt.
        key (bytes): Secret key for encryption.

    Returns:
        bytes: Ciphertext including IV + HMAC tag.

    Raises:
        ValueError: If encryption fails.
    """

References:

Function Description
encrypt Encrypt bytes or files with a key
decrypt Decrypt ciphertext with a key
BLOCK_SIZE Default block size (16 bytes)

Security Notice

This library is for educational purposes only. It implements a custom encryption scheme called Position-Dependent Encryption (PDE) and is not intended for real-world security.

Limitations:

  • Not resistant to side-channel attacks (timing, memory, cache analysis, etc.).
  • Tampering detection via HMAC is included, but the library cannot guarantee full integrity or authenticity in adversarial conditions.
  • Custom algorithms like PDE have not been audited and may contain unknown vulnerabilities.

For real-world encryption, always use standardized and audited cryptography such as:

  • AES-GCM
  • ChaCha20-Poly1305

Do not use this library for sensitive or production data.

Contributing

Feel free to submit pull requests or issues.
Ensure all tests pass before contributing.

License

MIT License (or your preferred license)

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

pdecrypto-0.1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

pdecrypto-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file pdecrypto-0.1.0.tar.gz.

File metadata

  • Download URL: pdecrypto-0.1.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pdecrypto-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b72b7714e4b4f7189b7cffae0419f045a0aada2b5d8ae3c12b8774fc9f1326ca
MD5 b39acd54adec17b742bc4fd7d59669a8
BLAKE2b-256 bbfdf6a1597e8d99ba91d65cb63fb017224492ce239cdf7d1bf634eb1f76ec5e

See more details on using hashes here.

File details

Details for the file pdecrypto-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pdecrypto-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pdecrypto-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f864223006c7d65c89ead05ea087d8dd08b137e1abdbeacd08cb69d7809a2994
MD5 78d58f8fe47b587437375013031b1360
BLAKE2b-256 e7d61e1e4ec14d52b9397d027cefae03a62b1cf1387f096bfb431af2fb3ac08d

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