If that's what you're trying to do, you needn't be so
devious. Instead, I would suggest using a PGP-type
signature and putting that in the "comment" field of the
GIF file. When you validate the GIF for authenticity,
you can strip the comment out and evaluate the image
for integrity. The GIF comment field should be able to
contain a regular signature, which is really just text.
This way, if the image is modified, the comment signature
will not check out, and since the signature is based on
a private key that they don't have, they can't forge a new
one. You could achieve the same thing with SHA1 or MD5
using a long and secure "passphrase" as well.
JPEG, as I have tried to emphasise, is a very bad idea
since the compression will pretty much destroy any subtle
fingerprinting you do on a bit level. A more sophisticated
"watermarking" technique is required in that case, and
these are generally non-trivial to implement, as they often
involve things like "fuzzy logic" to detect partial
patterns, or to correct damage done by the JPEG compression.
Your proposed four step process might seem sensible, but
the JPEG step is what is going to break it. Maybe I'm not
being clear enough about what "bit fiddling" will do
to your image.
Since both JPEG and GIF, and for that matter, PNG are
compressed, you cannot modify the bits and expect the
image to still be decompressible. The modification must
occur before the compression stage, on the bit-map data
that is sent to be compressed. You would have the same
trouble if you tried to apply your technique to a ZIP file,
to "sign it", and when the user tried to decompress this
damaged file, it would generate all sorts of CRC errors.
First, GIF and PNG have the property that the image you
put in, and the image you get out are identical, bit for bit.
GIF is somewhat limited, because you can only have up to
256 colors (8-bit, indexed color) out of a possible 24-bit
color space. PNG is better because you can have 16-bit
or 24-bit images, but with the same "exact" decompression
you'd expect from GIF.
JPEG, on the other hand, always destroys some information
in the process of compression. At maximum compression,
the image turns into a huge smudge. At minimum compression,
it might not look like much, but little 1 or 2 bit variations
are eliminated from the image to achieve the compression.
The higher the compression, the more the image is an
approximation of the original.
Here's a numeric representation of what might occur to
an image:
On the pixel level, the GIF and the original are identical,
since there are only 6 different colors used here. The
JPEG, though, by virtue of its "lossy" compression, results
in a smeared image, where groups of similar pixels are
averaged together to achieve compression. The subtle
differences between two colors are often eliminated, or
approximated using a pattern.
GIF compression works on a bit level, removing redundancy using
LZW data compression, the same sort of technique employed
by the ZIP program. JPEG uses a more sophisticated form
of compression that uses a Fourier transform, or in plain
English, a technique that strips out information that is
the least relevant. For instance, fine detail in the image
is the first to go, and as the compression increases,
the amount of detail you get decreases.
A curious thing to note is that JPEG is specifically intended
for use with images that are to be seen by the human eye.
Since the human eye is not particularly good at distinguishing
subtle changes in blue light, the blue in the RGB image
is compressed much more than the other two more visible
colors. You can see this if you split the image into
different channels, such as in Photoshop.