Skip to main content

Steganography algorithms (LSB, DCT, Spread Spectrum) with optional Reed-Solomon robustness

Project description

secure-stegano

Python steganography library implementing three algorithms (LSB, DCT, Spread Spectrum) with an optional error-correction layer (Reed-Solomon + repetition coding) and objective quality metrics.

Installation

pip install secure-stegano

Algorithms

LSB — Least Significant Bit (Spatial Domain)

Embeds message bits directly into the least significant bit of each pixel channel. Fast and high-capacity, but fragile against image processing.

from PIL import Image
from tpi_stegano import LSB

lsb = LSB()
cover = Image.open("cover.png")

stego = lsb.embed(cover, b"secret message")
message = lsb.extract(stego)  # b"secret message"

DCT — Discrete Cosine Transform (Frequency Domain)

Embeds bits into the mid-frequency DCT coefficients of 8×8 pixel blocks, inspired by JPEG steganography (JSteg/F5 principle). More resistant to visual detection than LSB.

from tpi_stegano import DCT

dct = DCT(quantization_step=25.0)
stego = dct.embed(cover, b"secret message")
message = dct.extract(stego)

Spread Spectrum (Frequency Domain)

Spreads each message bit across the entire DCT spectrum of the image using a pseudo-random carrier sequence derived from a secret key. Most robust algorithm against noise, filtering and compression.

from tpi_stegano import SpreadSpectrum

ss = SpreadSpectrum(key="my_secret_key", alpha=5.0)
stego = ss.embed(cover, b"secret message")
message = ss.extract(stego, message_length_bytes=len(b"secret message") + 3)

Robustness Layer

All three algorithms support an optional robust=True mode that applies Reed-Solomon error correction combined with repetition coding before embedding. This allows message recovery even after JPEG compression, Gaussian noise, cropping, rotation or blur.

# Embed with error correction
stego = lsb.embed(cover, b"secret message", robust=True)

# Extract — must use the same robust flag
message = lsb.extract(stego, robust=True)  # b"secret message"

The RobustCodec can also be used independently:

from tpi_stegano import RobustCodec

codec = RobustCodec(repetitions=3, ecc_symbols=10)
encoded = codec.encode(b"secret message")
recovered = codec.decode(encoded)  # b"secret message"

Quality Metrics

Objective metrics to evaluate and compare algorithm performance.

from tpi_stegano import psnr, capacity_bpp, ber, robustness_report

# Invisibility — higher is better (>40 dB = imperceptible)
score = psnr(cover, stego)

# Capacity — bits embedded per pixel
bpp = capacity_bpp(cover, message_bits=len(b"secret message") * 8)

# Bit Error Rate — 0.0 = perfect, 0.5 = random noise
error_rate = ber(original_bits, recovered_bits)

# Full robustness report across 6 attacks (JPEG, noise, crop, rotation, blur)
report = robustness_report(stego, original_bits, extract_fn=lambda img: lsb.extract(img))
# {
#   "jpeg_q75": 0.0,
#   "jpeg_q50": 0.04,
#   "gaussian_noise": 0.0,
#   "crop_10pct": 0.12,
#   "rotation_5deg": 0.21,
#   "blur": 0.0
# }

Algorithm Comparison

LSB DCT Spread Spectrum
Domain Spatial Frequency Frequency
Capacity High Medium Low
Invisibility (PSNR) ~50 dB ~40 dB ~35 dB
JPEG resistance Fragile Good Best
Noise resistance Fragile Medium Best
Requires key No No Yes

Dependencies

  • numpy >= 1.24
  • Pillow >= 10.0
  • scipy >= 1.11
  • reedsolo >= 1.7

License

MIT

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

secure_stegano-1.0.7.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

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

secure_stegano-1.0.7-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file secure_stegano-1.0.7.tar.gz.

File metadata

  • Download URL: secure_stegano-1.0.7.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for secure_stegano-1.0.7.tar.gz
Algorithm Hash digest
SHA256 7fe6331d37fa7e8e39dec5c9076ccf5912a8bececc00fc0753324444abc2f8bd
MD5 f42a0f7d75960b02e93ec60df0bca9a5
BLAKE2b-256 78130d218164c283232b9b8dac8b20d4ea3abcac1f44bad10d1970e47468ce2d

See more details on using hashes here.

File details

Details for the file secure_stegano-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: secure_stegano-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for secure_stegano-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 31d1110939547bdf3ed2828a547acb1a4102f0ace9fea6bb30351f34490e7114
MD5 048fa8b584157df4b27d89409373750f
BLAKE2b-256 882385c03b57fe54d1728c5494f40db14d8d21ba02260d59310f9f297c0af1ae

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