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

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.1.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.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pdecrypto-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 1f3410d4c9a474f0d2e6b86e40bb9a08893b1b996ca175fb6e19df63af3522aa
MD5 dbb72a0f393af34462523b3264e962f9
BLAKE2b-256 68036310e649c51952cb89f12889c1b823212f312b45d9fab04662f3928f4ee4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pdecrypto-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6d4fee9ac826601afcd24631b8f1a5b3fba81ae9723f21b2f586683abfc658de
MD5 e9a24eb50b2ec75681dd9b819c3bd02b
BLAKE2b-256 b82e203219c7a1e8871399f74bd67de92d55312188fe975f5e4619e5025bc44a

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