Skip to content

About

LSB-based Image Steganography in C — hides secret files inside BMP images using bitwise operations. Encode and decode with magic string verification.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

🖼️ LSB Image Steganography

A C implementation of LSB (Least Significant Bit) Steganography — hides secret files invisibly inside BMP images, and recovers them without any visible change to the image.

Built as part of the Emertxe Advanced C / Embedded Systems training (Skill India / NSDC — QP ELE/Q1501).


📌 What Is Steganography?

Steganography hides the existence of a message (unlike encryption, which hides the content). In this project, secret data is embedded into the least significant bits of BMP pixel bytes — a change invisible to the human eye.


🔑 LSB Technique

Each pixel byte of a 24-bit BMP image has 8 bits. Only the last bit (LSB) is modified:

Original pixel byte:  1 0 1 1 0 1 1 0
                                      ↑ LSB — only this bit changes
After embedding '1':  1 0 1 1 0 1 1 1

1 secret byte requires 8 image bytes (1 bit stored per image byte).


🗂️ File Structure

Steganography/
├── main.c          → CLI entry point, operation selector
├── encode.c        → Full LSB encoding logic
├── encode.h        → EncodeInfo struct + function declarations
├── decode.c        → Full LSB decoding logic
├── decode.h        → DecodeInfo struct + function declarations
├── types.h         → typedef: uint, Status, OperationType
├── common.h        → MAGIC_STRING "#*" definition
├── beautiful.bmp   → Source BMP image (input)
├── secret.txt      → Secret file to hide
├── stego.bmp       → Output BMP with hidden data (generated)
├── output.txt      → Recovered secret file (generated)
├── Makefile        → Build automation
└── README.md       → Documentation

⚙️ Build & Run

Compile

make

Encode (hide secret.txt inside beautiful.bmp)

./stego -e beautiful.bmp secret.txt stego.bmp
# or
make encode

Decode (recover secret from stego.bmp)

./stego -d stego.bmp output.txt
# or
make decode

Clean

make clean

📦 Data Layout in Stego Image

[ 54-byte BMP Header (unchanged) ]
[ Magic String "#*"  — 2 chars × 8 bytes = 16 bytes  ]
[ Extension Size     — 32 bytes (4-byte int in LSBs)  ]
[ Extension          — extn_size chars × 8 bytes      ]
[ Secret File Size   — 32 bytes (4-byte int in LSBs)  ]
[ Secret File Data   — file_size chars × 8 bytes      ]
[ Remaining image bytes unchanged                     ]

🧠 Key Concepts Used

  • Bitwise Operations — &, |, ~, <<, >> to extract and embed individual bits
  • File Handling — fopen, fread, fwrite, fseek, ftell, rewind
  • BMP Header — 54-byte structure; width at offset 18, height at offset 22
  • Enums — Status (e_success/e_failure), OperationType (e_encode/e_decode/e_unsupported)
  • Structures — EncodeInfo, DecodeInfo for grouping all operation state
  • Command-line Arguments — argc, argv[] for flexible CLI usage
  • Modular Design — encode.c / decode.c / types.h / common.h / main.c
  • Magic String — #* embedded as a signature to validate stego images

📋 Sample Execution

$ ./stego -e beautiful.bmp secret.txt stego.bmp
Selected encoding operation
Validation Successful. Starting encoding...
width = 1024
height = 768
Encoding Completed Successfully

$ ./stego -d stego.bmp output.txt
Selected decoding operation
Validation Successful. Starting decoding...
Magic string verified successfully
File extension: .txt
Secret file size: 12 bytes
Decoding successfull. Data written to output.txt
Decoded file successfully!

⚠️ Limitations

  • Supports only 24-bit BMP images (no PNG, JPG)
  • Maximum 100 contacts (compile-time, not a limit here — but image capacity is the constraint)
  • Image capacity = width × height × 3 bytes; secret data must fit within this
  • fopen uses "r" / "w" text mode (binary mode "rb" / "wb" would be more robust for BMP)
  • No password protection on the hidden data

👩‍💻 Author

Suchithra S
B.E. Electronics & Communication Engineering — Gopalan College of Engineering & Management (VTU), 2025
Advanced Embedded Systems Training — Emertxe Information Technologies
GitHub: github.com/suchithrasr
LinkedIn: linkedin.com/in/suchithrasr

About

LSB-based Image Steganography in C — hides secret files inside BMP images using bitwise operations. Encode and decode with magic string verification.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages