Skip to content

BUG: MathObfuscationConverter generates corrupted equations for carriage returns and tabs #4059

Closed

Description

@Kaap10

Describe the bug

MathObfuscationConverter converts text into algebraic equations of the form X = nX - (n - 1)X. In pyrit/converter/math_obfuscation_converter.py, the character loop only treats \n and " " as delimiters.

When input prompts contain Windows-style CRLF line breaks (\r\n), standalone carriage returns (\r), or horizontal tabs (\t):

  1. Carriage returns (\r): The loop fails to recognize \r as whitespace, generating an algebraic equation line for control character 0x0D (e.g. \r = 4\r - 3\r). When logged or displayed in terminals/consoles, the unescaped carriage return resets the cursor position to column 0, overwriting preceding terminal output.
  2. Horizontal tabs (\t): Generates an equation line (e.g. \t = 3\t - 2\t) rather than treating the tab as a whitespace word separator.

Steps/Code to Reproduce

import asyncio
from pyrit.converter import MathObfuscationConverter

async def main():
    converter = MathObfuscationConverter(hint="", suffix="")
    result = await converter.convert_async(prompt="hello\r\nworld\ttest")
    print(repr(result.output_text))

asyncio.run(main())

Expected Results

  • \r\n and standalone \r should normalize to standard newlines (blank line "" in the algebraic layout), matching the behavior of \n.
  • Horizontal tabs \t should be treated as whitespace word separators (blank line ""), matching the behavior of space " ".
  • Output should only contain algebraic equations for actual letters/characters:
'h = ...\ne = ...\nl = ...\nl = ...\no = ...\n\nw = ...\no = ...\nr = ...\nl = ...\nd = ...\n\nt = ...\ne = ...\ns = ...\nt = ...'

Actual Results

Contains equation lines for control characters:

'h = ...\n...\r = 7\r - 6\r\n\nw = ...\n\t = 4\t - 3\t\nt = ...'

Versions

  • OS: Windows 11
  • Python version: 3.12
  • PyRIT version: main

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions