Hi all !
I am new to programming and just finished the first section of my "The C Programming Language" book from Kernighan and Ritchie. Now I want to practice a little bit and write a program, which hides bits in png images.
Here is my approach.
I successfully did it with raw images like pnm but i don't know how to do it with compressed images. Is it even possible ? I think yes, because the png compression is lossless.
A little example: (link) my actual image is not 200x200 but 2x2.
[luk@silence][~/work/code/db/C]% hexdump -C rgb.pnm 00000000 50 36 0a 23 20 43 52 45 41 54 4f 52 3a 20 47 49 |P6.# CREATOR: GI| 00000010 4d 50 20 50 4e 4d 20 46 69 6c 74 65 72 20 56 65 |MP PNM Filter Ve| 00000020 72 73 69 6f 6e 20 31 2e 31 0a 32 20 32 0a 32 35 |rsion 1.1.2 2.25| 00000030 35 0a 64 64 64 ff 00 00 00 ff 00 00 00 ff |5.ddd.........| 0000003e
64 64 64 ff 00 00 00 ff 00 00 00 ff is the actual image data, but what is this:
[luk@silence][~/work/code/db/C]% hexdump -C rgb.png 00000000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 |.PNG........IHDR| 00000010 00 00 00 02 00 00 00 02 08 02 00 00 00 fd d4 9a |................| 00000020 73 00 00 00 16 49 44 41 54 08 d7 63 48 49 49 f9 |s....IDAT..cHII.| 00000030 cf c0 c0 c0 f0 9f 81 81 e1 3f 00 1e 0e 04 2a de |.........?....*.| 00000040 d2 d5 45 00 00 00 00 49 45 4e 44 ae 42 60 82 |..E....IEND.B`.| 0000004f
One way would be decompressing the file, hiding the bits and compressing it again, but is there another way ? A better way ?
You probably won't want to try to use the png data directly. Use a image file library. Libpng can be a read PITA, but imlib2 is good, cairo would also make this quite easy, but it may be overkill if you want to keep it light weight.
Note that pngs may have added bytes on each scanline. So moving forward 3*width bytes in an RGB image will not necessarily be down one row of pixels*.
edit: to clarify this is true even after the data is decompressed.
Last edited by Trilby (2013-06-09 14:59:04)
You could hide the bits in other fields in the PNG file, but that would be more obvious then hiding them in the image data.
Attempting to insert your data into the compressed image data will likely have a significant impact on the image due to the way that image data is compressed. There are a few different algorithms but all of them are row-based if I remember, so if you change the value of a pixel in one row in the compressed data, all subsequent rows of the image data will be affected at that position.
Decompression and recompression are indeed lossless, but the insertion of the data into the raw image data will likely change the size of the resulting compressed image data due to the way the compression algorithm works. Your changes will thus be detectable by simple size comparisons, but even if you somehow managed to get a file with the same size, the various checksums would be different anyway.
This detectability would only be the case if one had access to the original image as well.
Thank you for your answers !
but imlib2 is good
Ok, I'll try that, but im at the very beginning in C programming, therefore I only used the standard library so far.
@Xyne, it's just for practice. And maybe I give the picture to my friend, so that he can try to find the hidden data.