Python Steganography - Stepic

Using Stepic 0.3. I execute commands to encode the message in a jpg image. The code I use is as follows:

from PIL import Image import stepic im = Image.open ("tester.jpg") im2 = stepic.encode(im, '0987639987069730979076409784690y7689734') im2.save('stegtest.jpg') im1 = Image.open('stegtest.jpg') s = stepic.decode(im1) print s data = s.decode() print data 

However, the print data S and print give me a value, for example: 6 or some other strange character. I think that I am using functions as they should be used, why don't I get the right results?

+7
source share
1 answer

stepic 0.3 uses the simplest approach to steganography in images. Quoting directly from the module:

 def decode_imdata(imdata): '''Given a sequence of pixels, returns an iterator of characters encoded in the image''' imdata = iter(imdata) while True: pixels = list(imdata.next()[:3] + imdata.next()[:3] + imdata.next()[:3]) byte = 0 for c in xrange(7): byte |= pixels[c] & 1 byte <<= 1 byte |= pixels[7] & 1 yield chr(byte) if pixels[-1] & 1: break 

Each octet of sensitive data, plus a flag, whether the last byte, is hidden in three consecutive pixels. More precisely, stepic uses the least significant bits of the first three components (often RGB) of each pixel. See this very ugly diagram, for an RGBA stream with 4 bits per component ( D means data, E means end of stream):

  | pixel 0 | pixel 1 | pixel 2 | image viewer sees: | rrrr gggg bbbb aaaa | rrrr gggg bbbb aaaa | rrrr gggg bbbb aaaa | stepic sees: | ___D ___D ___D ____ | ___D ___D ___D ____ | ___D ___D ___E ____ | 

Since the noise introduced by this change is small in already β€œnoisy” images (one 256th), you often cannot really detect it visually. This means that the goal of this technique has been achieved: the data is hidden in view, because no one can distinguish it from natural noise.

It works. At least it works in lossless formats like PNG. Alas, JPG is not lossless, and its compression is likely to change at least one of the encoded bits. It is enough to change the ninth bit to make this method pretty useless, since the hidden data will be truncated to one byte.

Steganography in JPG images is still possible in many forms, but you cannot just adjust the decoded pixel values. The best (but more complicated) method may be to hide the data in the parameters evaluated by the compressor.

+5
source

All Articles