stegosphere.tools package

Submodules

stegosphere.tools.compression module

Helper functions for applying compression.

stegosphere.tools.compression.binary_compress(binary_string, method='lzma')

Compresses a binary string using lzma and returns the compressed binary string. The padding length is stored in the first 8 bits.

Parameters:
  • binary_string (str) – String of bits

  • method (str) – Compression method. Only lzma available.

Returns:

Compressed binary string.

Return type:

str

Raises:

NotImplementedError – if other method is used

stegosphere.tools.compression.binary_decompress(compressed_binary_string, method='lzma')

Decompresses a compressed binary string back to the original binary string.

Parameters:
  • compressed_binary_string (str) – Compressed string

  • method (str) – Compression method. Only lzma available.

Returns:

Decompressed binary string.

Return type:

str

Raises:

NotImplementedError – if other method is used

stegosphere.tools.compression.compress(string, method='lzma')

Compress a string using lzma or deflate (zlib) algorithm.

Parameters:
  • string (str) – The string to be compressed

  • method (str) – The method to be used. Either lzma or deflate

Returns:

the compressed string

Return type:

str

stegosphere.tools.compression.decompress(string, method='lzma')

Decompress a bytes object using lzma or deflate (zlib) algorithm.

Parameters:
  • string (str) – The compressed string

  • method (str) – The method to be used. Either lzma or deflate

Returns:

The decompressed string.

Return type:

str

stegosphere.tools.crypt module

Helper functions for applying cryptography.

class stegosphere.tools.crypt.AES_GCM

Bases: object

Applies AES-GCM

static decrypt(ciphertext, key)

Decrypts encrypted text using AES-GCM with key

Parameters:
  • ciphertext (str | bytes) – Cipher text to decrypt

  • key (str | bytes) – Encryption key

Returns:

decrypted payload

Return type:

str

static encrypt(payload, key, iv=None)

Encrypts payload using AES-GCM with key

Parameters:
  • payload (str | bytes) – Payload to encrypt

  • key (str | bytes) – Encryption key

  • iv (bytes | None, optional) – IV, else defaults to os.urandom(12)

Returns:

encrypted payload

Return type:

str

Raises:

AssertionError – If IV is not 12 bytes

stegosphere.tools.ecc module

Helper functions for error-correcting codes

class stegosphere.tools.ecc.Hamming7_4

Bases: object

Applies Hamming 7-4 code

static decode(payload)

Decodes Hamming-coded payload

Parameters:

payload (str) – Encoded payload

Returns:

Decoded payload

Return type:

str

Raises:

ValueError – If encoded string length is not a multiple of 7

static encode(payload)

Encodes payload with Hamming coding

Parameters:

payload (str) – Payload to encode

Returns:

Encoded payload

Return type:

str

stegosphere.tools.multifile module

A module for dividing payloads across several containers

stegosphere.tools.multifile.roundrobin_chunks(payload, num_instances)

Distribute the payload characters in round‑robin order.

Parameters:
  • payload – The full data string to split.

  • num_instances – How many interleaved sequences to produce.

Returns:

A list of num_instances strings, each containing every nth character.

stegosphere.tools.multifile.split_decode(instances, seed=None, distribution=None, distribution_args=None)

Decode payload from multiple stego‐instances.

Parameters:
  • instances – Callables returning stego‐data strings/bytes.

  • seed – If provided, re‐shuffle back into original order.

  • distribution – Same distribution used in encoding.

  • distribution_args – Args for reverse operations (if needed).

Returns:

The reconstructed payload string.

stegosphere.tools.multifile.split_encode(payload, instances, seed=None, distribution='even', distribution_args=None)

Encode a payload across multiple stego‐instances.

Parameters:
  • payload – The string to encode and split.

  • instances – Callables (e.g. functions) that take a chunk and return stego‐data.

  • seed – Optional PRNG seed to shuffle before splitting.

  • distribution – One of {‘even’, ‘weighted’, ‘roundrobin’}.

  • distribution_args – Extra args for distribution methods (e.g. {‘weights’: [0.2, 0.8]}).

Returns:

A list of stego‐encoded outputs, one per instance.

Raises:

ValueError – On unknown distribution or bad args.

stegosphere.tools.multifile.weighted_chunks(payload, num_instances, weights, tol=1e-06)

Split a payload into chunks sized according to given weights.

Parameters:
  • payload – The full data string to split.

  • num_instances – Number of desired chunks.

  • weights – Sequence of floats summing to ~1. Length must equal num_instances.

  • tol – Tolerance for sum(weights) == 1.0 check.

Returns:

A list of num_instances substrings in order.

Raises:
  • ValueError – If len(weights) != num_instances or weights don’t sum to ~1.

  • TypeError – If payload is not a str.

Module contents

The tools package provides various additional functionalities, which are encryption, Error correcting codes, compression, and payload distribution across multiple files.