pyrit.prompt_converter.BinAsciiConverter#

class BinAsciiConverter(*, encoding_func: Literal['hex', 'quoted-printable', 'UUencode'] = 'hex', indices: List[int] | None = None, keywords: List[str] | None = None, proportion: float | None = None, regex: str | Pattern | None = None, word_split_separator: str | None = ' ')[source]#

Bases: WordLevelConverter

Converts text to various binary-to-ASCII encodings.

Supports hex, quoted-printable, and UUencode formats.

__init__(*, encoding_func: Literal['hex', 'quoted-printable', 'UUencode'] = 'hex', indices: List[int] | None = None, keywords: List[str] | None = None, proportion: float | None = None, regex: str | Pattern | None = None, word_split_separator: str | None = ' ') None[source]#

Initialize the BinAsciiConverter.

Parameters:
  • encoding_func (str) – The encoding function to use. Options: “hex”, “quoted-printable”, “UUencode”. Defaults to “hex”.

  • indices (Optional[List[int]]) – Specific indices of words to convert.

  • keywords (Optional[List[str]]) – Keywords to select words for conversion.

  • proportion (Optional[float]) – Proportion of randomly selected words to convert [0.0-1.0].

  • regex (Optional[Union[str, re.Pattern]]) – Regex pattern to match words for conversion.

  • word_split_separator (Optional[str]) – Separator used to split words in the input text. Defaults to “ “.

Methods

__init__(*[, encoding_func, indices, ...])

Initialize the BinAsciiConverter.

convert_async(*, prompt[, input_type])

Converts the given prompt into the target format supported by the converter.

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

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

convert_word_async(word)

Convert a word using the specified encoding function.

get_identifier()

Returns an identifier dictionary for the converter.

input_supported(input_type)

Checks if the input type is supported by the converter.

join_words(words)

Join words appropriately based on the encoding type and mode.

output_supported(output_type)

Checks if the output type is supported by the converter.

validate_input(prompt)

Validates the input before processing (can be overridden by subclasses).

Attributes

EncodingFunc

alias of Literal['hex', 'quoted-printable', 'UUencode']

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.

EncodingFunc#

alias of Literal[‘hex’, ‘quoted-printable’, ‘UUencode’]

async convert_word_async(word: str) str[source]#

Convert a word using the specified encoding function.

Parameters:

word (str) – The word to encode.

Returns:

The encoded word.

Return type:

str

join_words(words: list[str]) str[source]#

Join words appropriately based on the encoding type and mode.

Parameters:

words (list[str]) – The list of encoded words to join.

Returns:

The joined string.

Return type:

str