In the previous recipes, we've looked at hiding images within another. This is all well and good, but our main aim of this chapter is to pass text that we can use in a command and control style format. The aim of this recipe is to hide some text within an image.
So far, we've looked at focusing on the RGB values of a pixel. In PNGs, we can access another value, the A
value. The A
value of RGBA
is the transparency level of that pixel. In this recipe, we are going to work with this mode, as it will allow us to store 8 bits in the LSBs of each value across two pixels. This means that we can hide a single char
value across two pixels, so we will need an image that has a pixel count of at least twice the number of characters we are trying to hide.
Let's look at the script:
from PIL import Image def Set_LSB(value, bit): if bit == '0': value = value & 254 else: value = value | 1 return value def Hide_message(carrier, message, outfile...