Split any binary, grayscale, or colour image into noise-like cryptographic shares that reveal nothing on their own — and reconstruct the secret only when the right shares are recombined.
Traditional encryption is heavy and breaks the moment a key leaks. Visual Cryptography (VC) takes a different route: a secret image is divided into several shares, each of which is pure statistical noise. No share — or any incomplete subset — reveals anything about the secret. Only by recombining the correct shares does the original image reappear, with little to no decryption cost.
CryptoSpectra is a clean, packaged re-implementation of the dissertation "Secure Image Sharing Using Visual Cryptography" (Krishita Choksi, School of Cyber Security & Digital Forensics, NFSU, 2025). It bundles five VC schemes for three image types behind a single library, a command-line tool, and an interactive dashboard, and it evaluates every reconstruction with PSNR, SSIM, NCORR, and SHA-256 hash integrity.
Use cases: healthcare imaging (X-rays, records), digital forensics, defence/CCTV, and any setting where a sensitive image must travel across an untrusted channel.
- 5 schemes across 3 image types — pick the right tool for the image (table below).
- Threshold sharing (2–8 shares) distributed across a simulated 1-server / 3-client network.
- Lossless reconstruction for XOR, Modular Arithmetic, Bit-Level Decomposition and Pixel Expansion (PSNR 100 dB, SSIM 1.0, exact hash match).
- Quality + integrity metrics built in: PSNR, NCORR, SSIM, SHA-256 hash match.
- Performance metrics — encryption/decryption time, peak memory, CPU usage.
- Three ways to use it: Python API,
cli.py, and a Streamlitdashboard.py. - Reproducible — optional RNG seed; exact-array (
.npy) share persistence.
| Image type | Scheme | Key | Shares | Pixel expansion | Reconstruction |
|---|---|---|---|---|---|
| Grayscale | XOR (N,N) | xor |
2–8 | no | Lossless |
| Grayscale | Modular Arithmetic (N,N) | modular |
2–8 | no | Lossless |
| Grayscale | Bit-Level Decomposition | bld |
2–8 | 2× | Lossless (extraction) |
| Binary | XOR (N,N) | xor |
2–8 | no | Lossless |
| Binary | Modular Arithmetic (N,N) | modular |
2–8 | no | Lossless |
| Binary | Pixel Expansion (2,2) | pe |
2 | 2× | Lossless (extraction) |
| Colour | XOR (N,N) | xor |
2–8 | no | Lossless |
| Colour | Modular Arithmetic (N,N) | modular |
2–8 | no | Lossless |
| Colour | CMYK Halftone | cmyk |
2 | no | Lossy |
How the security scales: missing a single XOR share leaves
2^(m·n)equally likely secrets; for Modular Arithmetic it is256^(m·n); for Pixel Expansion a single share needs6^(m·n)brute-force states — all computationally infeasible for any real image.
cryptospectra/
├── cli.py # unified command-line interface
├── dashboard.py # Streamlit interactive dashboard
├── requirements.txt
├── pyproject.toml
├── cryptospectra/ # the library
│ ├── algorithms/ # one module per scheme + a registry
│ │ ├── xor.py modular.py bld.py pixel_expansion.py cmyk.py
│ │ ├── base.py # common Scheme / SharesBundle interface
│ │ └── registry.py # (type, method) -> scheme lookup
│ ├── metrics/ # PSNR / NCORR / SSIM / hash (unified)
│ ├── network/ # server / client2 / client3 simulation
│ ├── pipeline.py # encrypt -> decrypt -> evaluate (+ resource stats)
│ ├── storage.py # share persistence (.npy + .png)
│ └── visualize.py # composite figures
├── data/
│ ├── input/
│ │ ├── grayscale/ # pebble, girl, dog
│ │ ├── binary/ # rings, flower
│ │ └── colour/ # blast, bomb, pebble, flower
│ └── output/
│ ├── shares/ decrypted/ reports/
└── docs/
└── Secure-Image-Sharing-Using-Visual-Cryptography-Report.pdf
Inputs are organised by image type; every run writes shares, the reconstructed image, and an
optional report figure into the matching data/output/ folder.
git clone https://github.com/Krishita17/cryptospectra.git
cd cryptospectra
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt# List every available (type, method) scheme
python cli.py methods
# Encrypt -> decrypt -> evaluate one image, save shares + a report figure
python cli.py run -i data/input/grayscale/pebble.png -t grayscale -m xor -s 4 --plot --save-shares
# Lossy colour example
python cli.py run -i data/input/colour/pebble.png -t colour -m cmyk
# Benchmark the dissertation's headline cases over the bundled samples
python cli.py demoClient–server distribution (1 server, 3 clients — threshold access control):
# Server: encrypt and split 4 shares (1 -> client1, 1 -> client2, rest -> client3)
python cli.py distribute -i data/input/colour/pebble.png --id pebble -t colour -m xor -s 4 --n1 1 --n2 1
# Client2: forward client1 + client2 shares to client3
python cli.py forward --id pebble
# Client3: gather all shares, reconstruct, and evaluate against the original
python cli.py combine --id pebble -t colour -m xor --original data/input/colour/pebble.pngstreamlit run dashboard.pyPick an image (upload or bundled sample), choose the image type, scheme, and share count, then watch the shares and the reconstruction appear side by side with full metrics, performance figures, and a difference heat-map.
from PIL import Image
from cryptospectra import run_pipeline, get_scheme
# One-shot pipeline with metrics + timing
result = run_pipeline(Image.open("data/input/grayscale/pebble.png"),
image_type="grayscale", method="xor", num_shares=4)
print(result.summary())
result.reconstruction.image.save("recovered.png")
# Or drive a scheme directly
scheme = get_scheme("colour", "modular")
bundle = scheme.encrypt(Image.open("data/input/colour/bomb.jpg"), num_shares=3)
recon = scheme.decrypt(bundle.shares)Reproduced from the dissertation on the Pebble test images (run python cli.py demo):
Grayscale (Table 4.2)
| Metric | XOR | Modular Arithmetic | BLD |
|---|---|---|---|
| PSNR | 100 dB | 100 dB | 100 dB |
| SSIM | 1.00 | 1.00 | 1.00 |
| Hash match | ✅ | ✅ | ✅ |
Binary (Table 4.3)
| Metric | XOR | Pixel Expansion |
|---|---|---|
| PSNR | 100 dB | 100 dB |
| SSIM | 1.00 | 1.00 |
| Hash match | ✅ | ✅ |
Colour (Table 4.4)
| Metric | XOR | Modular Arithmetic | CMYK Halftone |
|---|---|---|---|
| PSNR | 100 dB | 100 dB | ~33 dB |
| SSIM | 1.00 | 1.00 | 0.8028 |
| Hash match | ✅ | ✅ | ❌ (lossy) |
Performance highlights (Tables 4.5–4.7): XOR is the fastest and lightest scheme (~0.01 s, sub-MB). Modular Arithmetic is balanced. BLD is the most expensive (tens of seconds, ~1 GB peak) because it expands eight bit-planes — prefer XOR/MA unless 2× expansion is required.
┌──────────┐ encrypt + split shares ┌──────────┐
secret ─▶│ SERVER │ ─────────────────────────▶ │ client1 │─┐
└──────────┘ └──────────┘ │ forward
│ ┌──────────┐ │
├────────────────────────────────│ client2 │─┤
│ └──────────┘ │
└────────────────────────────────┐ ▼
▼ ┌─────────────┐
┌──────────┐│ client3 │
│ client3 ││ combined/ │─▶ decrypt + evaluate
└──────────┘└─────────────┘
The secret never travels whole. Each client holds only a slice of the shares; client3 can rebuild
the image only after client2 forwards the shares held by client1 and client2. This mirrors
the dissertation's threshold-access workflow and is implemented as a file-system simulation in
cryptospectra/network/ (no live sockets required).
| Metric | Meaning | Perfect value |
|---|---|---|
| PSNR | Peak signal-to-noise ratio (dB) — reconstruction fidelity | 100 dB (identical) |
| NCORR | Normalized cross-correlation between original and output | 1.0 |
| SSIM | Structural similarity (luminance/contrast/structure) | 1.0 |
| Hash | SHA-256 equality — integrity / tamper detection | match |
This is a re-organisation and clean-up of the original Visual-Cryptography-ongoing scripts. The
cryptographic logic is preserved so results match the dissertation, with these corrections:
- ~55 scattered scripts → one library + one CLI + one dashboard. The 27 near-duplicate
server*/client2*/client3*files collapse into a single parameterised simulation; the standalone*enc/*decscripts become reusable scheme modules behind a registry. - Categorised I/O. Inputs are split into
grayscale/,binary/,colour/; outputs intoshares/,decrypted/,reports/. - Exact share persistence. Shares are stored as
.npy(exact) alongside a.pngpreview, so reconstruction never loses fidelity to PNG re-quantisation. - Consistent NCORR. The earlier
normxcorr2Dzeroed perfectly-correlated regions, scoring identical images at ~0.03; the unified metric now correctly returns 1.0 for an exact match. - Vectorised CMYK. Per-pixel
getpixel/putpixelloops replaced with NumPy (same result, far faster). - Reproducibility + safety. Optional RNG seed; modern
numpy.random.default_rng; no fixed default seed leaking predictable shares. - Browser dashboard (Streamlit) replaces the Tkinter file-dialog GUI.
Krishita Choksi — B.Tech–M.Tech Computer Science Engineering (Cyber Security), NFSU, Gandhinagar. Supervised by Dr. Mukti Padhya.
The full dissertation is in docs/.
Released under the MIT License.