KGBCREST

Kingry Graphical Book Cipher Compression Resistant Encrypted Steganography Tool
Hide encrypted messages in images that survive JPEG compression down to quality 60.

View on GitHub Download ZIP

Features

🔐 AES-256 Encryption

Optional password-based encryption using AES-256-CBC with PBKDF2 key derivation.

📖 Book Cipher

Messages encoded as character positions in a shared source text file.

📸 JPEG Resistant

DCT watermarking survives JPEG compression down to quality 60.

🛡️ Error Correction

Reed-Solomon + repetition coding recovers from compression artifacts.

Quick Start

# Clone the repository
git clone https://github.com/akingry/KGBCREST.git
cd KGBCREST

# Install dependencies
pip install pillow numpy scipy reedsolo cryptography

# Run the tool
python server.py

Then open http://localhost:8080 in your browser.

How It Works

KGBCREST uses multiple layers of protection:

  1. AES-256 Encryption (optional) — Password-protected encryption
  2. Book Cipher — Characters encoded as positions in shared source text
  3. Compression — zlib reduces data size by 40-60%
  4. Error Correction — Reed-Solomon + 7× bit repetition
  5. DCT Watermarking — Embedded in frequency domain coefficients

DCT Watermarking Explained

The Discrete Cosine Transform (DCT) converts 8×8 pixel blocks from spatial domain (brightness values) into frequency domain (how quickly brightness changes). This is the same transform JPEG uses.

📊 Frequency Domain

DC coefficient: Average brightness
Low freq: Smooth gradients
Mid freq: Edges, textures — where we hide data
High freq: Fine detail — discarded by JPEG

🎯 Why Mid-Frequency?

JPEG preserves mid-frequencies (edges/structure) while discarding high frequencies. Hiding data here survives compression while remaining visually subtle.

Quantization Index Modulation (QIM)

To embed a bit, we quantize the DCT coefficient to encode 0 or 1:

Original coefficient: 127.3
Strength (quantization step): 150

To embed bit = 1:
  quantized = round(127.3 / 150) × 150 = 150
  modified  = 150 + (150 × 0.3) = 195

To embed bit = 0:
  quantized = round(127.3 / 150) × 150 = 150
  modified  = 150 - (150 × 0.3) = 105

Extraction:
  coefficient ≥ quantized → bit = 1
  coefficient < quantized → bit = 0

The Embedding Process

For each 8×8 block in the image:
  1. Extract block from luminance (Y) channel
  2. Apply 2D DCT transform
  3. Read coefficient at position (4,3)
  4. Modify coefficient using QIM to encode one bit
  5. Apply inverse DCT
  6. Write modified block back to image

This embeds one bit per 8×8 block. A 1920×1080 image has 32,400 blocks, yielding ~500 usable characters after error correction overhead.

Requirements