Least Significant Bit encoding — hide text inside an image, pixel by pixel
Step 1 — Choose a carrier image (PNG recommended)
▶ Click to show detailed explanation...
A digital image is nothing but a grid of pixels...
Each pixel is stored as three bytes: R,G,B — one byte each for red,green and blue intensity. Actually, PNG's can also have an ALPHA channel for transparency, so R,G,B,A. In this case it doesn't matter, its actually better since they are even less visible. Each byte holds a value from 0-255(dec) or 0xFF in hexadecimal and 11111111 in binary.(8-bits).
LSB - Least significant bit: Signifies the bit that changes the full byte the least when changed, in this case(11111111) the orange-colored bit
Example: 00000001 in binary is 128 in decimal
But: 10000000 in binary is only 1 in decimal
Therefor, we can use this least significant bit of every byte to add our coded message too. +1 or -1 R,G,B The difference is 1/255th or (0.4%) - invisible to the human eye.
🖼
Drop an image here or click to browse
Step 2 — Enter the secret message
▶ Click to show detailed explanation...
We take the message, convert it to a stream of bits (standard UTF-8 encoding), then write one bit into the LSB of each colour channel, sequentially: pixel 0's R channel gets bit 0, pixel 0's G channel gets bit 1, pixel 0's B channel gets bit 2, pixel 1's R channel gets bit 3, and so on. Try typing a message and stepping through it one bit at a time in Level 2.
Step 3 — Encode & download
▶ Click to show detailed explanation...
First, value & 0b11111110 — this is an AND with the mask 11111110. AND means "keep a bit only if both sides are 1". The mask has a zero at bit 0 and ones everywhere else, so it zeroes out the LSB while leaving the other 7 bits completely untouched. This is called clearing the bit.
Second, result | payloadBit — this is an OR with either 0 or 1. OR means "set a bit if either side is 1". If the payload bit is 1, bit 0 becomes 1. If it's 0, bit 0 stays 0. This is called setting the bit.
Combined: (value & 0b11111110) | bit