Skip to main content

Dynamic Image Encryption

Research-oriented Python implementation of a dynamic byte-level encryption algorithm using modular addition, modular subtraction, XOR and circular 8-bit rotation.

For each byte:

S_i = K_i mod 4

Then:

S=0 -> C=(P+K) mod 256
S=1 -> C=(P-K) mod 256
S=2 -> C=P XOR K
S=3 -> C=ROL(P,K mod 8)

Decryption applies the corresponding inverse operation.

Security note

This package is intended for research, experimentation and academic evaluation. It is not a replacement for established authenticated encryption schemes such as AES-GCM. No authentication/integrity mechanism is provided, and the key has the same length as the encrypted byte sequence.

Install

pip install "dynamic-image-encryption[all]"

Byte API

from image_encryption import encrypt, decrypt

ciphertext, key = encrypt(b"Hello")
plaintext = decrypt(ciphertext, key)

assert plaintext == b"Hello"

Image API

from image_encryption import encrypt_image, decrypt_image, save_key

key = encrypt_image("input.png", "encrypted.ienc")
save_key(key, "image.key")
decrypt_image("encrypted.ienc", key, "decrypted.png")

The image API works on decoded pixel bytes. Native Pillow modes are L, RGB and RGBA; other modes are converted to RGB. The decrypted conventional image is written as PNG.

NIfTI API

NIfTI voxel values are not reduced modulo 256. The raw bytes representing each voxel are encrypted. Thus an int16 voxel such as 7899 is encrypted as its two dtype/endianness-dependent bytes.

from image_encryption import encrypt_nifti, decrypt_nifti, save_key

key = encrypt_nifti("brain.nii.gz", "brain.ienc")
save_key(key, "brain.key")
decrypt_nifti("brain.ienc", key, "brain.decrypted.nii.gz")

The implementation stores the raw voxel dtype/shape, affine, NIfTI header, extensions and scaling information needed for reconstruction.

Tests

pip install -e ".[all,dev]"
pytest -q

Build

Change the PyPI name in pyproject.toml if the chosen name is already registered.

python -m build
python -m twine check dist/*
python -m twine upload --repository testpypi dist/*
python -m twine upload dist/*

Structure

image-encryption/
├── pyproject.toml
├── README.md
├── LICENSE
├── .gitignore
├── src/image_encryption/
│   ├── __init__.py
│   ├── core.py
│   ├── key.py
│   ├── operations.py
│   ├── container.py
│   ├── image.py
│   ├── nifti.py
│   └── exceptions.py
├── tests/
└── examples/

License

MIT.

Download files

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

Source Distribution

dynamic_image_encryption-0.1.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

dynamic_image_encryption-0.1.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for dynamic_image_encryption-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b0bc6601915d2522b320253e8eae09b56020b303850d3719d14c6af3e59578bb
MD5 b73283cbf515baad0016755ac488a4de
BLAKE2b-256 77944d391a3504c88c79b9d5a1020a47860ab148f3a5f04ede84ce959534e20a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dynamic_image_encryption-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ccc134ecb4e77dc96276a1e334201a0983f91ba79052cf1463d54dc88ef14b1
MD5 a20b9b1f2b335c9afcca2ea992165a44
BLAKE2b-256 6c9958438b3eee42d84128efff6adfc6a9b953ed5058c2f2388e8a11805f83a6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

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