Skip to content

TXTStegano

stegobox.codec.TXTStegano

Bases: BaseCodec

Program to hide a word in a text file. Convert the word into a binary string. At the end of each line of text in txt, decide whether to add a space according to the 0 and 1 of the binary string.

  • Created by: QiuYu
  • Created time: 2022/12/14

Originally implemented in avdvnk/Steganography-Lab1

Source code in stegobox/codec/txt_stegano/txt_stegano.py
class TXTStegano(BaseCodec):
    """Program to hide a word in a text file. Convert the word into a binary string.
    At the end of each line of text in txt, decide whether to add a space
    according to the 0 and 1 of the binary string.

    * Created by: QiuYu
    * Created time: 2022/12/14

    Originally implemented in
    [avdvnk/Steganography-Lab1](https://github.com/avdvnk/Steganography-Lab1)
    """

    def __init__(self) -> None:
        super().__init__()
        self.container = Container()

    def encode(self, carrier: list, payload: str) -> list:
        """Encoder requires carrier txt and payload to be a word.

        Args:
            carrier: Carrier text in format TXT. Read with
                `stegobox.io.txt.read_line()`.
            payload: Payload (secret message) to be encoded. Payload is a word.

        Returns:
            Encoded text in format txt with the payload embedded.
        """
        output_list = self.container.encrypt(carrier, payload)
        return output_list

    def decode(self, carrier: tuple[int, list]) -> str:
        """Decode the secret payload from the carrier txt.

        Args:
            carrier: Encoded carrier txt.

        Returns:
            The decoded payload (secret message).
        """
        key = self.container.decrypt(carrier)
        return key

encode(carrier, payload)

Encoder requires carrier txt and payload to be a word.

Parameters:

Name Type Description Default
carrier list

Carrier text in format TXT. Read with stegobox.io.txt.read_line().

required
payload str

Payload (secret message) to be encoded. Payload is a word.

required

Returns:

Type Description
list

Encoded text in format txt with the payload embedded.

Source code in stegobox/codec/txt_stegano/txt_stegano.py
def encode(self, carrier: list, payload: str) -> list:
    """Encoder requires carrier txt and payload to be a word.

    Args:
        carrier: Carrier text in format TXT. Read with
            `stegobox.io.txt.read_line()`.
        payload: Payload (secret message) to be encoded. Payload is a word.

    Returns:
        Encoded text in format txt with the payload embedded.
    """
    output_list = self.container.encrypt(carrier, payload)
    return output_list

decode(carrier)

Decode the secret payload from the carrier txt.

Parameters:

Name Type Description Default
carrier tuple[int, list]

Encoded carrier txt.

required

Returns:

Type Description
str

The decoded payload (secret message).

Source code in stegobox/codec/txt_stegano/txt_stegano.py
def decode(self, carrier: tuple[int, list]) -> str:
    """Decode the secret payload from the carrier txt.

    Args:
        carrier: Encoded carrier txt.

    Returns:
        The decoded payload (secret message).
    """
    key = self.container.decrypt(carrier)
    return key