Spaces:
Sleeping

File size: 4,813 Bytes
7ae71c6
 
 
 
 
 
 
 
 
2e3360a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d722d6a
7ae71c6
273abb6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
---
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
```bash
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.