Python-based LSB + AES steganography example
Steganography is a way to hide information for its secret keeping and transmission. By sense, it's specific sort of encryption - not by direct ciphering, but by mixing one information with other, in a way and proportion keeping hidden information invisible to other. More information about steganography you can find in article on Wikipedia. Here I just notice, that steganography (or "stego", how it named in jargon) sometimes used by cybersecurity specialists to hide important data and dispatches.
Despite in practice there could be very different ways of steganography, one of the most obvious is to hide data in big "haystacks" of bytes - i.e., in picture files. It's purely natural way. Typical picture file is, in one or other way, a huge (1024 x 1024 = 1048576) array of pixels, each of which, typically, encoded with at least 3 bytes (for red, green and blue channels). I.e., we have 1048576 x 3 = 3145728 bytes. Enough place to hide? Or not?
So, how to hide an information in the picture? One of the ways is adding 1 bit to LSB (least significant bit) to each byte of the image. I.e., for example, we have some digital image in raster graphics format (say, .bmp). In general, it's just an array of pixels. Each pixel, typically, presented by 3 bytes (1 for each channel). Let's take, say, red channel. It has 256 (2^8) levels of red intensity. Full red color then will be byte "11111111". If we change its LSB its value will become "11111110". The difference of result color is almost invisible for human eye. But - you saved there 1 bit of information! And with big pictures 1 bit per byte is not too small amount! For our example, 3145728 / 8 = 393216 bytes - almost 400 kB of data!
Of course, security experts knows about steganography, and able to track and extract embed data. I don't know details (never tried to do this), but knowing this guys, I'm 100% sure that there is enough even automated tools for detect hidden messages.
So, how to increase complexity of steganalysis for those who wants to find messages hidden in pictures? From what I know about theory of information and cryptanalysis - the main vulnerability is always an entropy of hidden message. Hidden data typically structured and organized, so its entropy is low. Using statistical methods, it's possible to detect that specific "channel" in message (picture in our case) has relatively low entropy - and this can be initial vector of attack. How to solve this? Increase the entropy of the message, i.e., encrypt it! Short before, I implemented an AES ciphering app. So my first idea when I've got the encrypted binary was to apply AES encryption system for hiding stego payload. Banal and primitive? Yes. But effective.
As educational example, I implemented simple steganography script, using Python, numpy and PYLLOW for operations with .png files. It works pretty simple - reading bytes of cover image into NumPy array, reading payload, then convert cover bytes in bit array, embed there a payload, and unload the result into stego picture.
Now, for example, we have a picture - say, a blueprints of "perspective and top-secret spacecraft" (of course, generated by ChatGPT 😊):
We need to transmit it safe where they need it, and we choose to use steganography for this. Let's do whole process step by step.
- First, we pack hidden image with my AES ciphering app into binary file payload.bin. As a password, we used
qwerty123(do notdo this at homeuse such password in real apps!) - Prepare the cover image. For this purpose I ordered ChatGPT to generate this picture with Thai street:
Interesting, that AI-generated pictures, which are slightly "dirty" and fuzzy by their nature, fits goals of steganography extremely good!
- Embed payload into cover with:
python steg_lsb_png.py embed cover.png payload.bin stego.png- As a result, we've got stego picture:
As you can see, it's extremely hard to notice visual difference between original and modified image!
- To extract the payload, those on receiving side can do:
python steg_lsb_png.py extract stego.png out_payload.bin
- Then, they need to decipher out_payload.bin with AES ciphering app, utilizing password we used - and viola, here's our revealed image:
This is an educational example of simple steganography. If you're stupid enough to use it in illegal purposes - you're on your own.
More detailed legal information you can get in License file.



