Question

I've seen a bunch of sample code that does a lot more than I want to do and it seems to have more overhead than I would like (perhaps this is unavoidable).

All I want is to hide/retrieve a 4 letter message (word) in/from a PNG file. These 4 letters will never change. It will always be the same 4 letters. It's purpose is simply to act as a simple kind of fingerprint. All of the examples I see seem very complex and involve compressing text files and such.

Does anyone know of any sample code that has been written that is relevant to this kind of endeavor? Any language is fine -- mine will eventually need to be C or Obj-C.

Was it helpful?

Solution

To hide data in a file, one must know something about what's expected there. If the file you're trying to hide stuff in has large areas of solid color, for example, changing even one pixel to an adjacent color could be noticeable.

If one assumes that a single-pixel shift to an adjacent color won't be noticeable, you could store 4 letters (20 bits) in a file by pseudo-randomly assigning the LSB of every red, green, or blue component of pixel to one of 20 bins, and then counting whether an even or odd number of pixel components in each bin have the LSB set. If the parity of a bin doesn't match the desired value for a bin, pick a pixel component arbitrarily/at random from among those assigned to that bin and arbitrarily/randomly increment or decrement it by one (if it's 0, you'll have to increment; if FF, decrement).

Decoding requires knowing the mapping of pixel components to the 20 bins, but even given a lot of pairs of unaltered and altered files wouldn't allow one to divine enough information to decode an arbitrary file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top