How prtmsh/steganography-py works
Project Type and Purpose
• This is a standalone Python command-line tool (an open-source steganography utility) for embedding and extracting invisible text watermarks in images using a border-hash based LSB scheme.
High-Level Architecture Overview
• The system can be broken down into four main domains:
a. Command-Line Interface (CLI) Layer
b. Core Watermarking Engine
c. Image I/O & Pre/Post-Processing
d. External Dependencies
Main Components
A. CLI Layer (src/main.py)
• Argument parser (mode, input path, output path, message)
• Dispatcher: invokes either Embed or Extract flow in the Core Engine
B. Core Watermarking Engine (src/watermark.py)
1. BorderExtractor & Hasher
• Reads outer 1-pixel border → computes SHA-256 hash
2. PRNG Seeder
• Uses hash as seed → generates reproducible pseudo-random interior pixel positions
3. Encoder (Embedding Flow)
• Prepend 16-bit length header to UTF-8 bitstream
• Embed bits into LSB of Blue channel of selected pixels
4. Decoder (Extraction Flow)
• Extract first 16 bits → recover message length
• Extract remaining bits → reconstruct UTF-8 text
5. Utility Functions
• Bit manipulation, header assembly/disassembly
C. Image I/O & Format Handling
• Uses Pillow/OpenCV/NumPy (from requirements.txt) to:
• Load input image
• Access and modify pixel buffers
• Save output as PNG (auto-convert other formats)
D. External Libraries
• OpenCV, NumPy, Pillow for image processing
• Python’s built-in hashlib for SHA-256
• Python’s built-in argparse for CLI
Component Interactions and Data Flow
1. User invokes CLI → src/main.py parses args
2. CLI calls watermark.Engine.embed() or .extract()
3. Engine loads image (ImageLoader) → passes pixel array to BorderExtractor
4. BorderExtractor → HashCalculator → seed to PRNG
5. PRNG → PixelSelector → either Encoder or Decoder
6. Encoder modifies pixel array → passed back to ImageSaver → writes watermarked PNG
7. Decoder reads pixel array → extracts bits → reconstructs text → prints result
Architectural Patterns & Principles
• Single-responsibility modules: each subcomponent (border hashing, PRNG, encoding, decoding) encapsulates one task
• Clear separation between CLI, core engine, and I/O concerns
• Deterministic design: border hash → repeatable PRNG sequence ensures reversible watermarking