Skip to main content

A python steganography package to insert/extract binary data into/from PNG files

Project description

bSteno

bSteno is a python module that allows users to insert and extract binary data (up to 16MB) to/from PNG files. The module doesn't modify the original PNG file and creates a new image instead.

The created PNG file is in RBGA format and the binary data is stored in the two LSBs of each channel. This means that 1 byte is stored in exacly one pixel of the image, with the following format:

  • The red channel contains bits 0-1
  • The green channel contains bits 2-3
  • The blue channel contains bits 4-5
  • The alpha channel contains bits 6-7

The presence of the alpha channel makes the image bigger than it could be, but I like the idea of having 1-pixel to 1-byte ratio as this simplifies the code quite a bit. This also makes it easier to extract the data if this scripts gets lost for some reason

The first three bytes/pixel of the image are used to store the size of the binary data. The size is stored in little endian

Installation

$ python3 -m pip install bsteno

Use the CLI

To insert the content of data.bin into source.png and store the output in output.png, run:

$ bsteno_insert --png-in=source.png --data-in=data.bin --png-out=output.png

To extract the binary data contained in output.png and store it in data.bin, run:

$ bsteno_extract --png-in=output.png --data-out=data.bin

Use bSteno as a library

bSteno can also be used as a library. It uses with the Pillow module to handle images.

To insert the content of data.bin into source.png and store the output in output.png, you can run the following code:

import PIL.Image
from bsteno import bsteno

img_in = PIL.Image.open("source.png")
with open("data.bin", "rb") as f:
	data = f.read()
img_out = bsteno.insert(img_in, data)
img_out.save("output.png", optimize=True)

bsteno.insert raises a DataTooBig exception if the data can't fit in the image.

To extract the binary data contained in output.png and store it in data.bin, you can run the following code:

import PIL.Image
from bsteno import bsteno

img_in = PIL.Image.open("output.png")
data = bsteno.extract(img_in)
with open("data.out", "wb") as f:
	f.write(data)

Development

This module uses poetry. After cloning the source code, run

$ poetry install

to prepare the virtual environment and install the cli tools. They can then be run with:

$ poetry run bsteno_insert ...
$ poetry run bsteno_extract ...

Running tests

$ poetry run python -m unittest

Code formatter

This project uses black code formatter

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bsteno-0.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bsteno-0.1.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file bsteno-0.1.0.tar.gz.

File metadata

  • Download URL: bsteno-0.1.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.7.3 Linux/5.10.103-v7+

File hashes

Hashes for bsteno-0.1.0.tar.gz
Algorithm Hash digest
SHA256 35a7e64b0675295f7e9553be457c26abdc90809e8b5de4798f3e6b06d7e906d6
MD5 3680182d2be6fb008aafd73fd03adc60
BLAKE2b-256 efc7f81f475ef8311bb4acef642c5e28905c26d6ef19965559bc70075f6de476

See more details on using hashes here.

File details

Details for the file bsteno-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: bsteno-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.7.3 Linux/5.10.103-v7+

File hashes

Hashes for bsteno-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb3fc50267ae22bd8edd15482e36e61d71a9edd0b6643105525c286100a32f72
MD5 8dc8b6802845c9775119fc58b7a69237
BLAKE2b-256 ec9c885fb534af75ec749a07a7093ab4981dfb02e551b74e556587feb569bbac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page