stegosphere.embeddings package

Submodules

stegosphere.embeddings.BPCS module

This implements Bit Plane Complexity Segmentation as based from: Kawaguchi, E., & Eason, R. O. (1999, January). Principles and applications of BPCS steganography. In Multimedia systems and applications (Vol. 3528, pp. 464-473). SPIE.

stegosphere.embeddings.BPCS.embed(array, payload, block_size=8, threshold=0.3)

Generalized BPCS embedding.

Parameters:
  • array (numpy.ndarray) – array to be embedded into

  • payload (str) – payload

  • block_size (int, optional) – Block size to use

  • threshold (float, optional) – Threshold

Returns:

(array, conj_map_records, used_bits)

stegosphere.embeddings.BPCS.extract(array, conj_map_records, total_bits, block_size=8)

Generalized BPCS extraction. conj_map_records = [(channel_idx, bitplane_idx, by, bx, was_conjugated), …] Returns binary string of length total_bits.

stegosphere.embeddings.LSB module

This implements Least Significant Bit steganography.

stegosphere.embeddings.LSB.embed(array, payload, matching=False, seed=None, indices=None, bits=1, framing=<class 'stegosphere.payloader.FixedHeader'>, framing_kwargs={})

Encodes a message into the cover data using LSB steganography, with optional LSB-matching, optional PRNG or custom indices, and both Python and C backends.

Parameters:
  • array (numpy.ndarray) – Cover object

  • payload (str) – String of binary numbers

  • matching (bool, optional) – Whether to use LSB matching (True) or LSB replacement (False). Only available with Python backend and bits=1.

  • seed (optional) – Seed for PRNG indices

  • indices (optional) – Indices to embed payload into. Can’t use seed and indices at the same time. Use PRNG selector strategies instead.

  • bits (int, optional) – Number of bits to change per value.

  • framing (stegosphere.payloader.PayloadFrame | None) – Type of framing used for payload

  • framing_kwargs (dict) – Specific arguments for payload framing

Returns:

Array with embedded payload

Return type:

numpy.ndarray

Raises:
  • ValueError – Not enough indices for embedding.

  • NotImplementedError – When using matching=True with more than one bits

Warns:

UserWarning – If array is too small, the payload will be shortened

stegosphere.embeddings.LSB.extract(array, seed=None, indices=None, bits=1, adaptive=False, framing=<class 'stegosphere.payloader.FixedHeader'>, framing_kwargs={})

Decodes a message from the cover data using LSB steganography. Works with LSB matching and replacement.

Parameters:
  • array (numpy.ndarray) – Cover object

  • seed (optional) – Seed for PRNG indices

  • indices (optional) – Indices to embed payload into. Can’t use seed and indices at the same time. Use PRNG selector strategies instead.

  • bits (int, optional) – Number of bits to extract per value.

  • framing (stegosphere.payloader.PayloadFrame | None) – Type of framing used for payload

  • framing_kwargs (dict) – Specific arguments for payload framing

Returns:

extracted payload

Return type:

str

stegosphere.embeddings.LSB.max_capacity(array, bits=1)

Calculates the maximum capacity of the cover object for embedding a message. The capacity is determined by the size of the data array and the number of bits available for modification. :param array: Cover object :type array: numpy.ndarray :param bits: Number of bits changed per value. Defaults to 1. :type bits: int, optional

Returns:

Maximum capacity of the object in bits

Return type:

int

stegosphere.embeddings.VD module

This is an adapted and generalised version of the Pixel Value Differencing method as proposed by Wu, D. C., & Tsai, W. H. (2003). A steganographic method for images by pixel-value differencing. Pattern recognition letters, 24(9-10), 1613-1626.

stegosphere.embeddings.VD.define_range(range_offset=3, range_start=1, range_range=(0, 255))

Defines ranges used in Value Differencing. Output format is [(bits changed, lower bound, upper bound),…] The bits changed in the lowest range is given by range_start. The upper bound in the lowest range is given by range_offset. The overall lower and upper bound is given by range_range.

Parameters:
  • range_offset (int, optional) –

  • range_start (int, optional) –

  • range_range (tuple, optional) –

stegosphere.embeddings.VD.define_range_table(ranges)

Return a list with fast access of bits to hide and bounds. Input can be output of define_range function.

Parameters:

ranges (list) – List of ranges in the format of [(bits to change, lower bound, upper bound), (bits to change + 1, lower bound, upper bound),…]

stegosphere.embeddings.VD.embed(array, payload, ranges=None, range_table=None, seed=None, framing=<class 'stegosphere.payloader.FixedHeader'>, framing_kwargs={})

Embed a payload into a cover array using Value Differencing steganography.

Parameters:
  • array (numpy.ndarray) – Cover object

  • payload (str) – String of binary numbers

  • ranges (list, optional) – pre-defined ranges

  • range_table (list, optional) – pre-defined range table

  • seed (optional) – Seed for PRNG indices

  • framing (stegosphere.payloader.PayloadFrame | None) – Type of framing used for payload

  • framing_kwargs (dict) – Specific arguments for payload framing

Returns:

Array with embedded payload

Return type:

numpy.ndarray

stegosphere.embeddings.VD.extract(array, ranges=None, range_table=None, seed=None, framing=<class 'stegosphere.payloader.FixedHeader'>, framing_kwargs={})

Extracts a payload from a cover array using Value Differencing steganography.

Parameters:
  • array (numpy.ndarray) – Cover object

  • ranges (list, optional) – pre-defined ranges

  • range_table (list, optional) – pre-defined range table

  • seed (optional) – Seed for PRNG indices

  • framing (stegosphere.payloader.PayloadFrame | None) – Type of framing used for payload

  • framing_kwargs (dict) – Specific arguments for payload framing

Returns:

extracted payload

Return type:

str

stegosphere.embeddings.echo_hiding module

Echo hiding steganography

stegosphere.embeddings.echo_hiding.detect_delay(frame, search_delays, alpha)

Detect which echo delay is present in an audio frame.

Performs autocorrelation of the frame and compares the peaks at specified delays to decide which echo was embedded.

Parameters:
  • frame (np.ndarray) – 1D audio frame.

  • search_delays (tuple of int) – Candidate delays (e.g., (delay0, delay1)).

  • alpha (float) – Expected echo attenuation factor (unused in detection but included for API consistency).

Returns:

The delay value from search_delays that yields the highest

autocorrelation peak, indicating the embedded bit.

Return type:

int

stegosphere.embeddings.echo_hiding.echo_kernel(delay, alpha, length)

Generate an echo impulse-response kernel.

Parameters:
  • delay (int) – Number of samples to delay the echo.

  • alpha (float) – Attenuation factor for the echo amplitude.

  • length (int) – Total length of the kernel in samples.

Returns:

1D kernel of shape (length,) with a direct-path impulse

at index 0 and an echo impulse at index delay.

Return type:

np.ndarray

stegosphere.embeddings.echo_hiding.embed(cover, bits, frame_size=1024, delay0=100, delay1=200, alpha=0.3)

Embed a bitstring into audio using echo hiding.

Splits the input signal into non-overlapping frames and applies either a short (delay0) or long (delay1) echo to encode ‘0’ or ‘1’ respectively.

Parameters:
  • cover (np.ndarray) – Input audio signal. May be 1D (mono) or 2D with shape (n_samples, n_channels).

  • bits (str) – Sequence of ‘0’/’1’ characters to embed.

  • frame_size (int, optional) – Number of samples per bit frame. Defaults to 1024.

  • delay0 (int, optional) – Echo delay in samples to encode a ‘0’ bit. Defaults to 100.

  • delay1 (int, optional) – Echo delay in samples to encode a ‘1’ bit. Defaults to 200.

  • alpha (float, optional) – Echo amplitude relative to the direct signal. Defaults to 0.3.

Returns:

Stego signal of same shape as cover, with embedded echoes.

Return type:

np.ndarray

stegosphere.embeddings.echo_hiding.extract(stego, n_bits, frame_size=1024, delay0=100, delay1=200, alpha=0.3)

Extract a bitstring from stego audio using echo hiding.

Splits the stego signal into frames and detects which delay was used to encode each bit.

Parameters:
  • stego (np.ndarray) – Stego audio signal, mono or (n_samples, n_channels).

  • n_bits (int) – Number of bits to extract.

  • frame_size (int, optional) – Number of samples per bit frame. Defaults to 1024.

  • delay0 (int, optional) – Echo delay used to encode ‘0’. Defaults to 100.

  • delay1 (int, optional) – Echo delay used to encode ‘1’. Defaults to 200.

  • alpha (float, optional) – Echo attenuation factor used in embedding. Defaults to 0.3.

Returns:

Extracted bitstring of length up to n_bits.

Return type:

str

Module contents

The embeddings package defines various embeddings for steganography. embedding and corresponding extraction are provided.