Hide secret files inside BMP images using Least Significant Bit (LSB) manipulation — written in pure C.
Steganography is the art of hiding secret information inside ordinary files without anyone noticing.
This tool embeds any secret file (.txt, .c, .csv, etc.) into a .bmp image by replacing the Least Significant Bit of each pixel byte with bits from the secret data. The resulting image looks visually identical to the original — but carries hidden information inside it.
Original BMP + Secret File → Stego BMP (looks identical, carries secret)
steganography-tool/
├── main.c # Entry point — argument parsing, operation routing
├── encode.c # Encoding logic — hides secret file into BMP
├── encode.h # Encoding function declarations & EncodeInfo struct
├── decode.c # Decoding logic — extracts secret file from BMP
├── decode.h # Decoding function declarations & DecodeInfo struct
├── common.h # Shared constants (MAGIC_STRING)
├── types.h # Custom types: Status, OperationType, uint
├── Makefile # Build automation
└── beautiful.bmp # Sample source image for testing
Source BMP → Copy 54-byte BMP Header
→ Encode Magic String (#*)
→ Encode Extension Size (32 bits)
→ Encode File Extension (.txt etc.)
→ Encode File Size (32 bits)
→ Encode File Data (LSB of each pixel byte)
→ Copy Remaining Image Data
→ Output: Stego BMP
Stego BMP → Verify Magic String (confirm stegged image)
→ Decode Extension Size
→ Decode File Extension
→ Decode File Size
→ Decode File Data
→ Output: Recovered Secret File
Each 1 byte of secret data is spread across 8 bytes of image data — 1 bit per pixel byte (LSB only). This causes a maximum pixel value change of ±1, making it visually undetectable.
// Encoding: set LSB of image byte to bit i of secret byte
image_buffer[i] = (image_buffer[i] & 0xFE) | ((data >> i) & 1);
// Decoding: extract LSB from each image byte, reconstruct secret byte
ch |= (image_buffer[i] & 1) << i;- GCC compiler
- Linux / Unix environment
- A
.bmpsource image
git clone https://github.com/santhoshpandiansg/steganography-tool.git
cd steganography-tool
makeOr manually:
gcc main.c encode.c decode.c -Wall -o stego./stego -e <source.bmp> <secret_file> [output.bmp]Example:
./stego -e beautiful.bmp secret.txt stego.bmpOutput:
[*] Operation : ENCODE
[*] Source BMP : beautiful.bmp
[*] Secret File: secret.txt
[*] Output BMP : stego.bmp
[1/7] Files opened successfully
[2/7] Capacity check passed
[3/7] BMP header copied
[4/7] Magic string encoded
[5/7] Extension size encoded
[6/7] Extension encoded: .txt
[7/7] Secret data encoded (22 bytes)
[+] Encoding Successful!
[+] Stego image saved as: stego.bmp
Decode — Extract hidden file from stego image
./stego -d <stego.bmp> [output_filename]Example:
./stego -d stego.bmp recoveredOutput:
[*] Operation : DECODE
[*] Stego Image : stego.bmp
[1/5] Stego image opened
[2/5] Magic string verified
[3/5] File extension decoded: .txt
[4/5] File size decoded: 22 bytes
[5/5] Secret data extracted successfully
[+] Decoding Successful!
[+] Secret file saved as: recovered.txt
| Concept | Where Used |
|---|---|
Bitwise operations (&, |, >>) |
LSB encode/decode |
Binary file I/O (fread, fwrite, rb, wb) |
All file operations |
| Struct-based design | EncodeInfo, DecodeInfo |
| Modular C programming | Separate encode/decode modules |
Memory management (malloc, free) |
Secret data buffer |
| BMP file format parsing | Header copy, pixel data access |
| Magic string validation | Tamper detection |
| Error handling with enums | Status, OperationType |
Max secret size (bytes) = (Image pixel bytes - overhead) / 8
Overhead = (MAGIC_STRING + extension_size(4) + extension + file_size(4)) * 8 bits
For a 800×600 BMP: 800 × 600 × 3 = 1,440,000 bytes → can hide up to ~179,000 bytes (~175 KB) of secret data.
- Only supports 24-bit uncompressed BMP images as cover files
- Secret file must fit within image capacity (tool checks this automatically)
- Not intended for security-critical use — LSB is a basic steganography technique
Santhosh Pandian SG Embedded Systems Engineer | Emertxe ECEP Trainee
This project is licensed under the MIT License.