惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
有赞技术团队
有赞技术团队
罗磊的独立博客
博客园 - 叶小钗
Jina AI
Jina AI
博客园 - 司徒正美
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
人人都是产品经理
人人都是产品经理
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
Microsoft Security Blog
Microsoft Security Blog
大猫的无限游戏
大猫的无限游戏
量子位
MyScale Blog
MyScale Blog
V
Visual Studio Blog
博客园 - 聂微东
The Cloudflare Blog
Engineering at Meta
Engineering at Meta
小众软件
小众软件
宝玉的分享
宝玉的分享

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
I Hid a Secret Message in a Cat Photo and Nobody Noticed ...
Aral Roca · 2026-04-30 · via DEV Community

Note: dev.to modifies the image, the original image with the secret is the original post 🤘

I found a steganography challenge in a CTF last year that had me staring at a picture of a cat for two hours. The image looked completely normal; 800x600 pixels of an orange tabby sitting on a keyboard. No metadata anomalies, no appended ZIP files, no obvious artifacts. The flag was hiding in the least significant bits of the blue channel. Once I extracted it, the message was 43 characters long. The cat hadn't changed at all.

That experience sent me down a rabbit hole. Steganography is one of those topics that sounds like movie-hacker fiction until you actually try it. Then you realize it's just math; and surprisingly simple math at that.

What steganography actually is

Steganography is the practice of hiding data inside other data so that nobody knows the hidden data exists. This is fundamentally different from cryptography. Encryption scrambles a message so it can't be read; steganography hides the message so nobody even looks for it.

The distinction matters. An encrypted file screams "I have secrets." A stego image says nothing. It's a photo of a cat. Or a sunset. Or your company logo. The best steganography produces carrier files that are statistically indistinguishable from unmodified originals.

The word itself comes from Greek: steganos (covered) + graphein (writing). It's been around since ancient Greece; Herodotus wrote about a guy who shaved a slave's head, tattooed a message on the scalp, waited for the hair to grow back, and sent the slave to deliver the message. We've upgraded to pixels since then.

How LSB encoding works

The most common image steganography technique is Least Significant Bit (LSB) encoding. Here's why it works.

A pixel in a 24-bit RGB image has three color channels, each stored as an 8-bit value (0-255). The last bit of each byte; the least significant bit; contributes the smallest possible change to the color value. Flipping it changes the channel value by exactly 1. The difference between RGB(142, 87, 203) and RGB(143, 87, 202) is invisible to the human eye.

So you take your secret message, convert it to binary, and replace the LSBs of the image pixels with your message bits. Each pixel gives you 3 bits of storage (one per channel). A 1920x1080 image has 2,073,600 pixels; that's 6,220,800 bits of storage, or roughly 760 KB of hidden data. In practice you'd use far less to avoid detection, but the theoretical capacity is enormous.

Here's a minimal Python implementation to make this concrete:

from PIL import Image
import numpy as np

def text_to_bits(text):
    """Convert text to a binary string with a null terminator."""
    bits = ''.join(format(ord(c), '08b') for c in text)
    bits += '00000000'  # null terminator to mark end of message
    return bits

def hide_message(image_path, message, output_path):
    """Hide a message in the LSBs of an image."""
    img = Image.open(image_path).convert('RGB')
    pixels = np.array(img)
    flat = pixels.flatten()

    bits = text_to_bits(message)
    if len(bits) > len(flat):
        raise ValueError(f"Message too long: need {len(bits)} bits, have {len(flat)}")

    for i, bit in enumerate(bits):
        # Clear the LSB, then set it to our message bit
        flat[i] = (flat[i] & 0xFE) | int(bit)

    stego = flat.reshape(pixels.shape)
    Image.fromarray(stego.astype('uint8')).save(output_path, 'PNG')
    print(f"Hidden {len(message)} chars in {len(bits)} bits ({len(bits)/len(flat)*100:.4f}% of capacity)")

def extract_message(image_path):
    """Extract a hidden message from the LSBs of an image."""
    img = Image.open(image_path).convert('RGB')
    flat = np.array(img).flatten()

    bits = ''.join(str(b & 1) for b in flat)
    chars = []
    for i in range(0, len(bits), 8):
        byte = bits[i:i+8]
        if byte == '00000000':
            break
        chars.append(chr(int(byte, 2)))
    return ''.join(chars)

# Usage
hide_message('cat.png', 'The flag is CTF{hidden_in_plain_sight}', 'stego_cat.png')
print(extract_message('stego_cat.png'))

Enter fullscreen mode Exit fullscreen mode

The key operation is on line 18: (flat[i] & 0xFE) | int(bit). The bitwise AND with 0xFE (11111110 in binary) clears the LSB, and the OR sets it to whatever our message bit is. That's the entire trick. Everything else is just converting text to bits and iterating over pixels.

Hiding a message step by step

If you don't want to write Python; or you're on a machine where you can't install PIL; the Steganography Tool on Kitmul does the same thing in your browser. No uploads, no server processing. The image never leaves your device.

Here's the workflow:

  1. Upload a carrier image. PNG works best because it's lossless. JPEG compression will destroy your hidden bits; more on that later.
  2. Type your secret message. The tool shows you the available capacity based on your image dimensions.
  3. Download the stego image. It looks identical to the original. Pixel-for-pixel, the differences are imperceptible.

To extract, switch to Reveal mode, upload the stego image, and the hidden text appears.

The steganography tool showing Hide mode with upload area, secret message input, and download button

The entire operation runs client-side using the Canvas API and typed arrays. Your secret message never touches a network connection. This matters; if you're hiding sensitive information, sending it to a third-party server rather defeats the purpose.

Detection and steganalysis; how to NOT get caught

Steganalysis is the art of detecting steganography, and it's more sophisticated than you might think.

Visual inspection won't catch LSB encoding. But statistical analysis will. The simplest test is a chi-squared analysis of pixel value distributions. In a natural image, pixel values have a characteristic distribution. LSB embedding flattens pairs of values (e.g., 142 and 143 become equally probable), which shows up as an anomaly in the histogram.

Tools like StegExpose and OpenStego include detection modules. In competitive CTF environments, zsteg and steghide are the go-to extraction tools.

Here are practical tips if you want your stego image to survive scrutiny:

  • Use less capacity. Embedding data in only 10-20% of available pixels makes statistical detection much harder. Using 100% of capacity is a forensic red flag.
  • Randomize pixel selection. Instead of writing sequentially from pixel 0, use a pseudorandom sequence seeded by a password to select which pixels carry data. This distributes the modifications uniformly.
  • Choose busy images. Photos with lots of texture, noise, and color variation hide LSB changes better than smooth gradients or solid blocks. A photo of a forest floor beats a photo of a white wall.
  • Never use JPEG as a carrier. JPEG's lossy compression modifies pixel values during encoding. Your hidden bits will be destroyed when the image is saved. Always use PNG, BMP, or TIFF for LSB steganography.
  • Strip metadata before sharing. EXIF data showing the image was processed by a steganography tool is an obvious giveaway.

When to combine steganography with encryption

Steganography and encryption solve different problems, and the strongest approach uses both. Here's why.

If an attacker suspects your image contains hidden data and successfully extracts the LSBs, they'll see your plaintext message. Game over. But if you encrypt the message first; using AES-256, for example; the extracted bits look like random noise. The attacker can't tell whether they found a message or just normal image data.

The practical workflow:

  1. Encrypt your message with a strong symmetric cipher.
  2. Hide the ciphertext in the image using LSB encoding.
  3. Share the stego image publicly.
  4. Share the decryption key through a separate channel.

This gives you two layers of protection: the message is both hidden (steganography) and unreadable (encryption). An attacker would need to both detect the hidden data and crack the encryption; a significantly harder problem than either alone.

Kitmul's Security and Cryptography tools include AES encryption, hash generators, and other utilities that complement the steganography tool for this exact workflow.

Real-world use cases

Steganography isn't just a CTF party trick. It has legitimate and important applications.

Digital watermarking. Publishers, photographers, and media companies embed invisible watermarks in images to track unauthorized distribution. If a leaked image surfaces, the embedded watermark identifies which recipient leaked it. This is how several major movie studios track screener copies.

Whistleblowing and censorship resistance. In countries with heavy internet surveillance, steganography allows activists to share information through innocent-looking images posted on social media. The image passes inspection by automated content filters; the hidden message reaches its intended audience.

Covert communication. Intelligence agencies have used steganography since at least the early 2000s. The FBI's 2010 arrest of Russian spies (the "Illegals Program") revealed they were embedding encrypted messages in images posted to public websites.

CTF challenges. Capture The Flag competitions love steganography because it tests a different skill set than standard crypto challenges. You need to identify that steganography was used at all before you can begin extraction. Common CTF stego techniques include LSB encoding, appended data, palette manipulation in GIF files, and audio spectrum hiding.

Proof of ownership. Artists and content creators can embed copyright information or ownership proofs directly into their work. Unlike visible watermarks, these don't degrade the visual quality of the piece.

A system of linear equations on paper; the math behind steganography is simpler than it looks

The limits of pixel encoding

LSB steganography has real constraints worth understanding. The carrier image must be lossless; any lossy compression step (JPEG, WebP lossy) will corrupt embedded data. The message capacity scales with image dimensions, but using more than about 15-20% of capacity makes the image vulnerable to statistical detection. And the technique only hides data; it doesn't protect it from extraction by someone who knows what to look for.

For most practical purposes, image steganography works best as one layer in a defense-in-depth strategy. Hide the message, encrypt the content, and use a secure channel to share the key. No single technique is bulletproof, but the combination raises the bar significantly.

Try it yourself

The Steganography Tool on Kitmul lets you hide and reveal messages in PNG images directly in your browser. Everything runs client-side; no data is uploaded, no accounts required, no limits. Upload an image, type a message, download the result. Then try extracting it to verify the round trip.

If you're interested in security and privacy tools, the Security and Cryptography collection includes hash generators, encryption tools, password generators, and more; all running locally in your browser.


All processing runs locally in your browser. No images or messages are sent to any server. The tool is free, open, and has no accounts or limits.