pyrit.prompt_converter.AsciiSmugglerConverter#

class AsciiSmugglerConverter(action: Literal['encode', 'decode'] = 'encode', unicode_tags: bool = False)[source]#

Bases: SmugglerConverter

Implements encoding and decoding using Unicode Tags.

If ‘control’ is True, the encoded output is wrapped with:
  • U+E0001 (start control tag)

  • U+E007F (end control tag)

Replicates the functionality detailed in the following blog post: https://embracethered.com/blog/posts/2024/hiding-and-finding-text-with-unicode-tags/

__init__(action: Literal['encode', 'decode'] = 'encode', unicode_tags: bool = False)[source]#

Initialize the converter with options for encoding/decoding.

Parameters:

unicode_tags (bool) – Whether to add Unicode tags during encoding.

Methods

__init__([action, unicode_tags])

Initialize the converter with options for encoding/decoding.

convert_async(*, prompt[, input_type])

Convert the prompt by either encoding or decoding it based on the specified action.

convert_tokens_async(*, prompt[, ...])

Converts substrings within a prompt that are enclosed by specified start and end tokens.

decode_message(*, message)

Decodes a message encoded with Unicode Tags.

encode_message(*, message)

Encodes the message using Unicode Tags.

get_identifier()

input_supported(input_type)

Return True if the input type is 'text'.

output_supported(output_type)

Return True if the output type is 'text'.

Attributes

supported_input_types

Returns a list of supported input types for the converter.

supported_output_types

Returns a list of supported output types for the converter.

decode_message(*, message: str)[source]#

Decodes a message encoded with Unicode Tags.

For each character in the Unicode Tags range, subtracts 0xE0000. Skips control tags if present.

Parameters:

message (str) – The encoded message.

Returns:

The decoded message.

Return type:

str

encode_message(*, message: str)[source]#

Encodes the message using Unicode Tags.

Each ASCII printable character (0x20-0x7E) is mapped to a corresponding Unicode Tag (by adding 0xE0000). If control mode is enabled, wraps the output.

Parameters:

message (str) – The message to encode.

Returns:

A tuple with a summary of code points and the encoded message.

Return type:

Tuple[str, str]