File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import logging
2+ from typing import Optional
23from stego_llm .steganography import (
34 chunks_to_message ,
45 find_acceptable_token ,
1718
1819
1920def main_decode (
20- encoded_prompt ,
21- initial_prompt ,
22- chunk_size ,
23- num_logprobs ,
24- llm_path = None ,
25- ):
26- """Main decoding function for steganographic message extraction."""
21+ encoded_prompt : str ,
22+ initial_prompt : str ,
23+ chunk_size : int ,
24+ num_logprobs : int ,
25+ llm_path : Optional [str ] = None ,
26+ ) -> Optional [bytes ]:
27+ """Decodes a message hidden in a text.
28+
29+ This function extracts a hidden message from a text that was encoded
30+ using steganography. It uses a language model to determine the likely
31+ sequence of tokens that represent the hidden message.
32+
33+ Args:
34+ encoded_prompt (str): The text containing the hidden message.
35+ initial_prompt (str): The initial text used to start the encoding process.
36+ chunk_size (int): The number of bits per chunk used for encoding.
37+ num_logprobs (int): The number of token probabilities to consider.
38+ llm_path (Optional[str]): The path to the language model file.
39+ If None, the default model is used.
40+
41+ Returns:
42+ Optional[bytes]: The decoded message as bytes, or None if decoding fails.
43+ """
2744 llm = create_llm_client (model_path = llm_path )
2845 message_carrying_text = encoded_prompt [len (initial_prompt ) :]
2946 memo = {}
Original file line number Diff line number Diff line change 11import logging
2+ from typing import Optional
23from stego_llm .steganography import (
34 message_to_chunks ,
45 find_acceptable_token ,
1718
1819
1920def main_encode (
20- initial_prompt ,
21- msg ,
22- chunk_size ,
23- num_logprobs ,
24- llm_path = None ,
25- ):
26- """Main encoding function for steganographic text generation."""
21+ initial_prompt : str ,
22+ msg : bytes ,
23+ chunk_size : int ,
24+ num_logprobs : int ,
25+ llm_path : Optional [str ] = None ,
26+ ) -> str :
27+ """Encodes a message into a text using steganography.
28+
29+ This function hides a message within a carrier text generated by a language
30+ model. It embeds the message by selecting specific tokens based on the
31+ message's binary representation.
32+
33+ Args:
34+ initial_prompt (str): The starting text to prompt the language model.
35+ msg (bytes): The message to be hidden, as a byte string.
36+ chunk_size (int): The number of bits from the message to encode in each step.
37+ num_logprobs (int): The number of next-token probabilities to request from the LLM.
38+ llm_path (Optional[str]): The path to the language model file.
39+ If None, the default model is used.
40+
41+ Returns:
42+ str: The generated text with the message embedded within it.
43+ """
2744 llm = create_llm_client (model_path = llm_path )
2845 enc_ints = message_to_chunks (msg , chunk_size = chunk_size )
2946 current_prompt = initial_prompt
You can’t perform that action at this time.
0 commit comments