Skip to content
Tutorials Center
My learning

Topics

Lesson 32 of 40 ยท Protocols and Practice

Steganography: Hiding Data in Plain Sight

Learn how steganography differs from cryptography, hide a message in the least significant bits of image data, see why it is fragile and how steganalysis detects it.

Encryption makes a message unreadable. Steganography (from the Greek for "covered writing") hides the fact that a message exists at all. A letter written in invisible ink, a microdot under a stamp and a few secret bits tucked into a photograph are all steganography. The carrier looks innocent, so nobody thinks to attack it.

Cryptography and steganography answer different questions and are often combined:

Cryptography Steganography
Goal Protect the content Hide the existence
What an observer sees Obvious ciphertext A normal-looking file
If detected Message still unreadable Message is exposed (unless also encrypted)
Analysis of an attack Cryptanalysis Steganalysis

The safe pattern is to encrypt first, then hide. Encrypted data looks like random bytes, which also makes it blend better into noisy carriers, and even if the hiding is found the content stays private. Relying on hiding alone is "security through obscurity", which Kerckhoffs's principle warns against.

Where data can hide

Almost any medium with redundancy works:

  • Images: the least significant bits of pixel values, or coefficients in a JPEG.
  • Audio and video: tiny changes in samples or frames that the ear and eye cannot notice.
  • Text: unusual spacing, zero-width Unicode characters or the choice between synonyms.
  • File structure: bytes appended after the end of a valid file, unused header fields and metadata (EXIF comments).
  • Network traffic: values in unused protocol header fields or packet timing.

Least-significant-bit (LSB) hiding

A grayscale or RGB pixel channel is a number from 0 to 255. Changing the lowest bit shifts it by at most 1, a difference of less than 0.4% that the eye cannot see. So each channel byte can carry one hidden bit: clear its lowest bit and put the message bit there. To read the message, collect the lowest bit of each byte again.

The program below hides text in a synthetic "image" (a list of byte values, standing in for decoded pixels), recovers it, and measures how much the image changed.

Python Hide and recover a message with LSB steganography

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Capacity is the weak point: one bit per byte means an image can carry only about one eighth of its own size, and carrying more means changing more bits, which makes detection easier.

Why it is fragile, and how steganalysis works

LSB hiding survives only if the pixels are stored exactly. Lossy compression (saving as JPEG, resizing, filtering, a messenger app re-encoding the photo) rewrites the pixel values and destroys the hidden bits. Robust schemes hide data in frequency coefficients instead, at a cost in capacity.

Steganalysis is the art of detecting hidden data. Natural images have correlated lowest bits and statistics a message disturbs. A classic test compares how often neighbouring values pair up (the chi-square attack): when you overwrite lowest bits with random message bits, the counts of values 2k and 2k+1 become artificially equal.

Python A simple statistical test for LSB embedding

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The imbalance collapses toward zero as more of the carrier is overwritten, because random message bits make 2k and 2k+1 equally likely. That equalization is the signature an analyst looks for. The toy data is deliberately skewed to make the effect obvious; real tools run far more sophisticated versions of this test.

Tools you will meet in practice

Security analysts and capture-the-flag players use standard programs to look for or extract hidden data. They are listed here for recognition; they are not runnable in this page.

  • steghide embeds and extracts data in JPEG and WAV files, protected by a passphrase.
  • zsteg looks for LSB patterns in PNG and BMP images.
  • ExifTool reads and edits metadata, where comments and coordinates often hide.
  • binwalk scans a file for embedded or appended files and signatures.
  • stegsolve is a viewer that flips through bit planes and colour channels of an image.
  • Audacity shows spectrograms, where text can be drawn into the frequency picture of audio.

Digital watermarking is a close relative with the opposite aim: the hidden mark identifies the owner of a picture or song and must survive editing, whereas steganography prioritizes secrecy.

Advantages and disadvantages

Advantages: hides that communication is happening, which matters under censorship, and can add a second layer to encryption. Disadvantages: low capacity, fragility under compression, no protection once found unless the payload is encrypted, large carriers (and so long transmission times) for modest messages, and it is also a tool of malware authors who hide payloads in images.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the main difference between cryptography and steganography?

    Steganography conceals the existence of the message, cryptography conceals its meaning.
  2. 2. How much can LSB embedding change one 8-bit pixel value?

    Only the lowest bit is replaced, so the value moves by 0 or 1.
  3. 3. Why does re-saving a stego image as a lossy JPEG usually destroy the message?

    LSB hiding needs exact pixel values; lossy compression changes them.
  4. 4. What is the recommended order when you want both secrecy and hiding?

    Encrypting first keeps the content private even if the hiding is discovered, and random-looking ciphertext blends into noise.

Summary

  • Steganography hides the existence of data; cryptography hides its meaning. Use both: encrypt, then hide.
  • LSB hiding stores one message bit per carrier byte with an invisible change, but capacity is small and lossy compression destroys it.
  • Steganalysis detects the statistical traces that embedding leaves behind.
  • Tools such as steghide, zsteg, ExifTool, binwalk and stegsolve are the analyst's standard kit.

Next: Project: Encrypted Vault, where you combine key derivation, encryption and authentication into one small application.