0

I am trying to encode text into picture and then decode it using stepic module. When i execute below code it gaves me decode error. Kindly, advice how to fix it.

#encode text in photo
from PIL import Image
import stepic
im=Image.open("beer.jpg")
im2=stepic.encode(im,"In god we trust")
im2.save("stegbeer.jpg","JPEG")

#decode text from photo
im1=Image.open("stegbeer.jpg")
s=stepic.decode(im1)
data=s.decode()
print data

Error: Traceback (most recent call last): File "C:\Users\xxxx\Desktop\Python\steganography\all.py", line 11, in data=s.decode() UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)

ussrback
  • 491
  • 2
  • 8
  • 22

1 Answers1

0

Like nneonneo suggested, stepic doesn't work with jpeg. From the online documentation:

Since the data is stored in the colors, not in any format specific manner, Stepic can be write to PNG, BMP, and other formats, and can read a whole slew of others. (JPEG doesn’t work, since it throws out data.)

Stepic uses 3 lsb embedding directly to the pixels. Any lossy compression format that affects the pixel values is unsuitable. If you want to work with jpeg images, you have to use a different, more suitable algorithm.

Reti43
  • 9,656
  • 3
  • 28
  • 44