This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Stegano is a pure Python steganography module that provides multiple techniques for hiding messages in images and audio files. The codebase is structured around independent steganography techniques, each with a hide() and reveal() interface.
# Run all tests
python -m unittest discover -v
# Run a single test file
python -m unittest tests.test_lsb -v
# Run a specific test case
python -m unittest tests.test_lsb.TestLSB.test_hide_and_reveal -v# Run mypy static type checker
mypy stegano# Run pre-commit hooks manually
pre-commit run --all-files
# Install pre-commit hooks
pre-commit installcd docs
pip install -r requirements.txt
make htmlThe module provides four main steganography techniques, each in its own submodule:
-
LSB (Least Significant Bit) -
stegano/lsb/- Primary technique using pixel LSB manipulation
- Supports custom generators for pixel selection (see Generators below)
- Main API:
lsb.hide(image, message, generator=None, shift=0)andlsb.reveal(encoded_image, generator=None, shift=0)
-
Red Channel -
stegano/red/- Uses only the red channel of RGB pixels
- Simpler but more limited (max 254 characters)
- Main API:
red.hide(input_image, message)andred.reveal(input_image)
-
EXIF Headers -
stegano/exifHeader/- Embeds messages in JPEG/TIFF EXIF metadata
- Uses base64 encoding and compression
- Main API:
exifHeader.hide(input_image_file, img_enc, secret_message=None, secret_file=None)andexifHeader.reveal(input_image_file)
-
WAV Audio -
stegano/wav/- Hides messages in uncompressed WAV audio files
- Uses LSB of PCM samples
- Main API:
wav.hide(input_file, message, output_file)andwav.reveal(input_file)
The LSB technique supports pluggable generators (in stegano/lsb/generators.py) that determine which pixels are used for encoding. This makes steganalysis more difficult by scattering the message according to mathematical sequences:
identity()- Sequential pixels (default)eratosthenes()- Prime numbers via Sieve of Eratosthenesfibonacci()- Fibonacci sequencemersenne()- Mersenne primestriangular_numbers()- Triangular numbersfermat()- Fermat numbersackermann(m)- Ackermann functionLFSR(m)- Linear-feedback shift registershi_tomashi(image_path, ...)- OpenCV corner detection
The same generator must be used for both hiding and revealing.
stegano/tools.py contains shared classes and utilities:
Hiderclass - Handles message encoding into imagesRevealerclass - Handles message extraction from images- Bit manipulation functions (
setlsb,a2bits,a2bits_list) - Image handling (
open_image)
stegano/steganalysis/ provides tools to detect steganography:
parity.py- LSB parity detectionstatistics.py- Statistical analysis
stegano/console/ contains CLI entry points defined in pyproject.toml:
stegano-lsb- LSB technique CLIstegano-red- Red channel technique CLIstegano-steganalysis-parity- Parity analysis CLIstegano-steganalysis-statistics- Statistical analysis CLI
All steganography techniques follow the pattern:
hide(input, message, [options]) -> output- Returns PIL Image or writes to filereveal(input, [options]) -> str- Returns decoded message
- Uses PIL (Pillow) for image operations
- LSB techniques work with RGB/RGBA modes (auto-conversion available)
- Red channel technique requires RGB
- Images are opened via
tools.open_image()which accepts file paths, file objects, or PIL Images
- Default encoding is UTF-8 (8 bits per character)
- UTF-32LE (32 bits) also supported
- Message length is encoded in the output for extraction
Tests are in tests/ directory:
- Sample files in
tests/sample-files/ - Expected output images in
tests/expected-results/ - Each technique has its own test file (e.g.,
test_lsb.py,test_red.py) - Generators have dedicated tests in
test_generators.py