A flexible steganography and steganalysis library supporting various file types, including encryption and compression
Project description
Stegosphere
A flexible steganography and steganalysis library for image, audio, ttf, multiple file and all NumPy-array-readable steganography, including encryption and compression.
Install via pip:
pip install stegosphere
It is meant to be usable for research by combining steganography and steganalysis, see Research toolbox.
Table of contents
- General usage
- Image steganography
- Audio steganography
- ttf steganography
- Multimedia steganography
- File handling
- Compression and Encryption
- Additional parameters
- More file types
- Research toolbox
- Contributing
General
The library is made to allow for generalisation and compatability of different steganographical methods across file types. The base steganography classes define steganography on top of numpy arrays, while the implementations for different file types primarily aid in converting between the file type and numpy arrays.
Currently, methods for image, audio, ttf, video and multi-file steganography are implemented.
Image steganography
For image steganography, LSB (Least Significant Bit), PVD (Pixel Value Differencing), BPCS (Bit-Plane Complexity Segmentation) and IWT (Integer Wavelet Transform) steganography are currently available.
The example loads an image into a container and writes a payload into the pixels and then reads it out again.
from stegosphere.containers.image import ImageContainer
from stegosphere.methods import LSB
from stegosphere.io import *
img = ImageContainer('image.png')
px = img.read()
cover = LSB.embed(px, 'Embedded message!', method='delimiter')
img.flush(cover)
img.save('image_stego.png')
steg_img = ImageContainer('image_stego.png')
steg_px = steg_img.read()
uncover = LSB.extract(steg_px, method='delimiter')
print(binary_to_data(uncover))
#Expected output: 'Embedded message!'
For additional parameters, see the chapter on parameters.
Audio steganography
For audio steganography, LSB (Least Significant Bit), FVD (Frequency Value Differencing) and IWT (Integer Wavelet Transform) steganography are currently available.
The example below loads an audio and encodes the file image.png into the audio. The image is then recovered and saved.
from stegosphere.containers.audio import WAVContainer
from stegosphere.methods import VD
from stegosphere.io import file_to_binary, binary_to_file
wav = WAVContainer('audio.wav')
bin_image = file_to_binary('image.png')
frames = wav.read()
embedded = VD.embed(frames, bin_image)
wav.flush(embedded)
wav.save('steg_audio.wav')
steg_wav = WAVContainer('steg_audio.wav')
steg_frames = steg_wav.read()
extracted = VD.extract(steg_frames)
binary_to_file(extracted,'recovered_image.png')
For additional parameters, see the chapter on parameters.
ttf steganography
For ttf steganography, LSB (Least Significant Bit) and Custom Table steganography are currently available.
The example below stores a string into a custom created table within the TTF file.
from stegosphere.containers.ttf import TTFContainer
from stegosphere.methods import ttf_CustomTable
font = TTFContainer('font.ttf')
embedded = ttf_CustomTable.embed(font, 'Encoded message!', table_name='STEG')
embedded.save('steg_font.ttf')
steg_font = TTFContainer('steg_font.ttf')
print(ttf_CustomTable.extract(steg_font, 'STEG'))
Multifile steganography
It is also possible to divide the payload across different files.
Different methods and parameters can be used for each file where data is being encoded.
Below, the content of the file payload.png is distributed randomly (with a seed) across the files image.png and audio.wav, with LSB and FVD being used.
from stegosphere.containers import image, audio
from stegosphere.methods import LSB, VD
from stegosphere.tools import multifile
from stegosphere import io
data = io.file_to_binary('payload.png')
img = image.ImageContainer('image.png')
aud = audio.WAVContainer('audio.wav')
px = img.read()
frames = aud.read()
img_encode = lambda payload: LSB.embed(px, payload)
aud_encode = lambda payload: VD.embed(frames, payload)
#the encoded image pixels and audio frames
IMG, AUD = multifile.split_encode(data, [img_encode, aud_encode], seed=42)
#flush encoded data into file objects
img.flush(IMG)
aud.flush(AUD)
img.save('stego_image.png')
aud.save('stego_audio.wav')
#Extracting
img = image.ImageContainer('stego_image.png')
aud = audio.WAVContainer('stego_audio.wav')
px, frames = img.read(), aud.read()
img_extract = lambda: LSB.extract(px)
aud_extract = lambda: VD.extract(frames)
output = multifile.split_decode([img_extract, aud_extract], seed=42)
assert output == data
The payload can be distributed evenly (default setting), using weighted distribution or roundrobin.
File handling
Several functions for file handling are provided.
stegosphere.io.file_to_binary(path) --> converts any file into binary for encoding.
stegosphere.io.binary_to_file(binary_data, output_path) --> saves binary back into file format.
stegosphere.io.data_to_binary(data) --> converts any string into binary for encoding.
stegosphere.io.binary_to_data(binary) --> converts a binary string into a readable bytes object.
Compression and encryption
Additionally, compression and encryption are provided.
Compression can be used by setting compress='lzma' when encoding/decoding. The given message will then be (de)compressed using lzma.
Compression can also be used on its own, by using compression.compress/compression.decompress. lzmaand deflate algorithm are currently available.
Additional parameters
| Parameter | Available for | Effect |
|---|---|---|
seed |
LSB, VD, multifile | Distributes payload pseudorandomly across the file. Reduces detectability drastically. |
matching |
in development for LSB | less detectable way of adapting bits in LSB |
bits |
LSB | increases capacity, increases detectability |
method |
LSB, VD | The method to detect end of message when decoding. Either 'delimiter', 'metadata' or None. |
metadata_length |
LSB, VD | Bits used at the beginning of the message for the metadata. Change only needed for very short or very long (>0.5GB) payloads. |
delimiter_message |
LSB, VD | The message used as an end of message signifier when decoding. |
compress |
LSB, VD | Compress message to save space when encoding. |
More file types
Any file types which can be read or converted as a numpy array can be used for some of the steganographic methods, which are implemented in the methods folder.
Research toolbox
The steganography and steganalysis modules can be combined to create research pipelines. Below is an example of measuring how different measures (speed, PSNR, ...) change when increasing the payload of an image, using LSB, for a set of images from a folder.
import pandas as pd
from stegosphere.methods import LSB
from stegosphere.utils import generate_binary_payload as gbp
from stegosphere.analysis import efficiency, imperceptibility, detectability, accuracy
from stegosphere.containers import ContainerCollection
from stegosphere.containers import image
import os
path = os.listdir('PATH_TO_IMAGE_DIRECTORY')
images = ContainerCollection(path, image.ImageContainer, filter=True)
pxs = images.read()
df = pd.DataFrame(columns=['image', 'capacity','psnr','embed efficiency', 'detector','accuracy','extract efficiency'])
#test for different images
for path, px in zip(images.paths, pxs):
max_capacity = LSB.max_capacity(px) - LSB.METADATA_LENGTH_LSB
max_payload = gbp(capacity)
#test for differrent payload sizes
for cap in range(0, max_capacity, max_capacity//10):
#Embedding efficiency
with efficiency.Timer() as embed_time:
emb = LSB.embed(px, max_payload[:cap])
#Imperceptibility
p = imperceptibility.psnr(px, emb, 255)
#Detectability
d = detectability.uniformity_detector(emb)
#Extraction efficiency
with efficiency.Timer() as extract_time:
ext = LSB.extract(emb)
#Extraction accuracy
acc = accuracy.bit_error_rate(ext, max_payload[:cap])
#Store results
df.loc[len(df)] = path, cap, p , embed_time.diff, d, acc, extract_time.diff
print(df)
Contributing
Any support or input is always welcomed. Additional general methods are much needed.
Contact:
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stegosphere-1.2.1.tar.gz.
File metadata
- Download URL: stegosphere-1.2.1.tar.gz
- Upload date:
- Size: 63.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
755990eb63ff3db2fcc1833c004808b3cb01bb148c2c5afb0d889e1ca1f68c8c
|
|
| MD5 |
17a566f5edbc1250b8908f7e831e1a86
|
|
| BLAKE2b-256 |
1d7c0dd466e24c8d1144e1b375f9bedeb28eac206b5ee75ce1eae6a431e23a56
|
File details
Details for the file stegosphere-1.2.1-py3-none-any.whl.
File metadata
- Download URL: stegosphere-1.2.1-py3-none-any.whl
- Upload date:
- Size: 67.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd5241f982376528fbdb7babcdd253d57e5de7bc9e513ec3de83572e52ec04f0
|
|
| MD5 |
87c1c4e82919468e51826d072ddd1191
|
|
| BLAKE2b-256 |
4294cfd8525f1738db00a19e31dea01ce63749b329778057241ce13b22bd1396
|