Metadata-Version: 2.4
Name: dynamic-image-encryption
Version: 0.1.0
Summary: Research-oriented dynamic byte-level image and NIfTI encryption library.
Author-email: Safouane Akrimi <safouaneakrimi@gmail.com>
License: MIT
Keywords: image encryption,cryptography,NIfTI,medical imaging,security
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: image
Requires-Dist: numpy>=1.24; extra == "image"
Requires-Dist: Pillow>=10.0; extra == "image"
Provides-Extra: nifti
Requires-Dist: numpy>=1.24; extra == "nifti"
Requires-Dist: nibabel>=5.0; extra == "nifti"
Provides-Extra: all
Requires-Dist: numpy>=1.24; extra == "all"
Requires-Dist: Pillow>=10.0; extra == "all"
Requires-Dist: nibabel>=5.0; extra == "all"
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: twine>=5.0; extra == "dev"
Dynamic: license-file

# 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:

```text
S_i = K_i mod 4
```

Then:

```text
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

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

## Byte API

```python
from image_encryption import encrypt, decrypt

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

assert plaintext == b"Hello"
```

## Image API

```python
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.

```python
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

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

## Build

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

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

## Structure

```text
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.
