Skip to content

HideWAVinWAV

stegobox.codec.HideWAVinWAV

Bases: BaseCodec

This algorithm allows to conceal audio files inside audio, using a well known steganographic method: hide the data in the least significant bits. Make encode and decode flexible with regards to sample-bits and number of channels. It currently only supports 16bit/stereo.

  • Created by: QiuYu
  • Created time: 2023/1/4

Originally implemented in ichaelo/audio_steganagraphy

Source code in stegobox/codec/hide_wavinwav/hide_wavinwav.py
class HideWAVinWAV(BaseCodec):
    """This algorithm allows to conceal audio files inside audio, using a well
    known steganographic method: hide the data in the least significant bits.
    Make encode and decode flexible with regards to sample-bits and number
    of channels. It currently only supports 16bit/stereo.

    * Created by: QiuYu
    * Created time: 2023/1/4

    Originally implemented in
    [ichaelo/audio_steganagraphy](https://github.com/michaelo/audio_steganagraphy)
    """

    def __init__(self) -> None:
        super().__init__()

    def encode(self, _):
        raise NotImplementedError("This codec does not support encoding without bits")

    def encode_with_bits(
        self, bits: int, carrier: wave.Wave_read, payload: wave.Wave_read
    ) -> tuple[bytes, tuple]:
        """Encoder requires carrier audio to be WAV and payload to be a WAV audio.

        Args:
            bits: Sample bits.
            carrier: Carrier audio in WAV. Read with `stegobox.io.audio.read_r()`.
            payload: Payload (secret message) to be encoded. Payload in WAV. Read with
                `stegobox.io.audio.read_r()`.

        Returns:
            sample: Frame information in bytes of the audio with the payload embedded.
            params: Parameters for audio with the payload embedded.
        """
        sample, params = ed.encode(bits, carrier, payload)
        # imgout = self.img.encode(carrier, bits_array)
        return sample, params

    def decode(self, _):
        raise NotImplementedError("This codec does not support decoding without bits")

    def decode_with_bits(
        self, carrier: wave.Wave_read, bits: int
    ) -> tuple[bytes, tuple]:
        """Decode the secret payload from the carrier audio.

        Args:
            carrier: Encoded carrier audio. Read with `stegobox.io.audio.read_r()`.
            bits: Sample bits.

        Returns:
            sample: Frame information in bytes of the audio revealed.
            params: Parameters for audio revealed.
        """
        sample, params = de.decode(bits, carrier)
        return sample, params

encode_with_bits(bits, carrier, payload)

Encoder requires carrier audio to be WAV and payload to be a WAV audio.

Parameters:

Name Type Description Default
bits int

Sample bits.

required
carrier Wave_read

Carrier audio in WAV. Read with stegobox.io.audio.read_r().

required
payload Wave_read

Payload (secret message) to be encoded. Payload in WAV. Read with stegobox.io.audio.read_r().

required

Returns:

Name Type Description
sample bytes

Frame information in bytes of the audio with the payload embedded.

params tuple

Parameters for audio with the payload embedded.

Source code in stegobox/codec/hide_wavinwav/hide_wavinwav.py
def encode_with_bits(
    self, bits: int, carrier: wave.Wave_read, payload: wave.Wave_read
) -> tuple[bytes, tuple]:
    """Encoder requires carrier audio to be WAV and payload to be a WAV audio.

    Args:
        bits: Sample bits.
        carrier: Carrier audio in WAV. Read with `stegobox.io.audio.read_r()`.
        payload: Payload (secret message) to be encoded. Payload in WAV. Read with
            `stegobox.io.audio.read_r()`.

    Returns:
        sample: Frame information in bytes of the audio with the payload embedded.
        params: Parameters for audio with the payload embedded.
    """
    sample, params = ed.encode(bits, carrier, payload)
    # imgout = self.img.encode(carrier, bits_array)
    return sample, params

decode_with_bits(carrier, bits)

Decode the secret payload from the carrier audio.

Parameters:

Name Type Description Default
carrier Wave_read

Encoded carrier audio. Read with stegobox.io.audio.read_r().

required
bits int

Sample bits.

required

Returns:

Name Type Description
sample bytes

Frame information in bytes of the audio revealed.

params tuple

Parameters for audio revealed.

Source code in stegobox/codec/hide_wavinwav/hide_wavinwav.py
def decode_with_bits(
    self, carrier: wave.Wave_read, bits: int
) -> tuple[bytes, tuple]:
    """Decode the secret payload from the carrier audio.

    Args:
        carrier: Encoded carrier audio. Read with `stegobox.io.audio.read_r()`.
        bits: Sample bits.

    Returns:
        sample: Frame information in bytes of the audio revealed.
        params: Parameters for audio revealed.
    """
    sample, params = de.decode(bits, carrier)
    return sample, params