Spaces:
Sleeping

crypto-api / README.md
low-key-007's picture
Update README.md
d722d6a verified
|
Raw History Blame Contribute Delete
4.81 kB
metadata
title: Crypto Api
emoji: 🐨
colorFrom: indigo
colorTo: blue
sdk: docker
pinned: false
license: mit

Crypto-Stego API (FastAPI + Docker)

A lightweight API wrapper around your three modules:

  • sender.py β€” encrypts the cover image and produces two Fernet keys.
  • embbed.py β€” embeds a secret image into the encrypted image and appends a third key.
  • retreive.py β€” reconstructs the encrypted image and retrieves the secret image.

Endpoints

  1. POST /encrypt β€” form-data with image (file). Returns:

    • encrypted_image (download URL)
    • aes_key, aes_key_2
    • run_dir (use for subsequent steps)
  2. POST /embed β€” form-data with:

    • run_dir (string from /encrypt response)
    • secret_image (file)
      Returns:
    • stego_image (download URL)
    • secret_shuffle_key
  3. POST /retrieve β€” form-data with:

    • run_dir
    • JSON body: { "aes_key": "...", "aes_key_2": "...", "secret_shuffle_key": "..." }
      Returns:
    • constructed_image, retrieved_secret_image (download URLs)
    • Metrics: RMSE and entropy

Each request runs inside an isolated runs/<uuid> directory to avoid cross-request collisions.

Run locally

docker build -t crypto-stego .
docker run -p 7860:7860 crypto-stego

if you want to test or acces my website follow this link : "https://kaleidoscopic-platypus-4af4a4.netlify.app/"
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference






# πŸ” CipherStego: Secure Block-Based Image Steganography

![Python](https://img.shields.io/badge/Python-3.10-blue?logo=python&logoColor=white)
![FastAPI](https://img.shields.io/badge/Framework-FastAPI-green?logo=fastapi&logoColor=white)
![Cryptography](https://img.shields.io/badge/Security-AES_Fernet-red)
![Status](https://img.shields.io/badge/Research-Prototype-orange)

> **CipherStego** is a hybrid security framework combining **Cryptography** and **Steganography**. It utilizes a dual-layer shuffling mechanism (Block & Pixel permutation) combined with LSB (Least Significant Bit) insertion to ensure high visual imperceptibility and robust data hiding.

---

## πŸ”¬ Abstract & Methodology
Traditional steganography is vulnerable to steganalysis if the cover image statistical properties are altered significantly. CipherStego mitigates this by encrypting the cover image *before* embedding, a technique known as **Encrypted Domain Data Hiding**.

### Key Algorithms:
1.  **Block Permutation (Key 1):** The image is divided into $2 \times 2$ matrices. The positions of these blocks are shuffled using a chaotic map generated by a Fernet key.
2.  **Intra-Block Diffusion (Key 2):** Pixels within each block are permuted to destroy local correlation.
3.  **LSB Embedding (Key 3):** The secret image is flattened and embedded into the Least Significant Bits of the encrypted cover.

---

## πŸ— System Architecture

The system operates on a **3-Key Authentication** principle. 
* **Level 1 Access:** View the "Constructed" (Encrypted) image.
* **Level 2 Access:** Decrypt the cover image.
* **Level 3 Access (Root):** Extract the hidden secret image.


```mermaid
graph TD
    subgraph "Sender Side"
        Cover[πŸ–ΌοΈ Cover Image]
        Secret[🀫 Secret Image]
        
        Cover -->|Key 1: Block Shuffle| Encrypt[πŸ”’ Encrypted Domain]
        Encrypt -->|Key 2: Pixel Shuffle| Encrypt
        
        Secret -->|Key 3: Bit Stream| Embedder[πŸ“₯ LSB Embedder]
        Encrypt --> Embedder
        Embedder --> Stego[πŸ“¦ Stego Image]
    end

    subgraph "Receiver Side"
        Stego -->|Input| Extractor[πŸ“€ Data Extractor]
        
        Extractor -->|Keys 1 & 2| Construct[πŸ–ΌοΈ Reconstruct Cover]
        Extractor -->|Key 3| Hidden[🀫 Extract Secret]
    end





πŸ“Š Performance Metrics
The system evaluates the quality of the steganography using standard research metrics:

RMSE (Root Mean Square Error): Measures the difference between the original cover and the reconstructed image. Lower is better. $$ RMSE = \sqrt{\frac{1}{MN} \sum (I_{orig} - I_{stego})^2} $$

Entropy: Measures the randomness of the encrypted image. A value closer to 8 (for 8-bit images) indicates better encryption.






Component,Technology,Description
Backend,FastAPI,Asynchronous REST API for handling image uploads.
Crypto,Fernet (AES),Symmetric key encryption for shuffling vectors.
Processing,NumPy,High-performance matrix manipulation for 2x2 blocks.
Imaging,Pillow (PIL),Image I/O and format conversion.




πŸ‘¨β€πŸ’» Developer's Note
This project was developed to explore the trade-offs between Embedding Capacity and Visual Imperceptibility. Future improvements include implementing Discrete Cosine Transform (DCT) for frequency-domain embedding to improve resistance against compression attacks.