O'Reilly logo

Python: Penetration Testing for Developers by Dave Mound, Benjamin May, Andrew Mabbitt, Terry Ip, Cameron Buchanan, Mohit, Christopher Duffy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Extracting text from images

In the previous recipe, we saw how to hide text in the RGBA values of an image. This recipe will let us extract that data out.

How to do it…

We saw in the previous recipe that we split up a characters byte into 8 bits and spread them over the LSBs of two pixels. Here's that diagram again as a refresher:

How to do it…

The following is the script that will do the extraction:

from PIL import Image from itertools import izip def get_pixel_pairs(iterable): a = iter(iterable) return izip(a, a) def get_LSB(value): if value & 1 == 0: return '0' else: return '1' def extract_message(carrier): c_image = Image.open(carrier) pixel_list = list(c_image.getdata()) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required