Repository navigation
FEAT: Add runic/ogham (Leetspeak configs) + mirror/upside_down Encoding techniques - #4455
Roman Lutz (romanlutz) wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The concrete CharacterMapConverter helper is automatically registered and exposed as a usable converter, but its empty mapping silently leaves prompts unchanged.
1 open issue
What changed in this PR
This PR adds four text-obfuscation converters to PyRIT, sharing character-mapping logic and integrating them into the Garak Encoding scenario.
Changes:
- Adds Runic, Ogham, Mirror, and UpsideDown converters with lazy public exports.
- Includes all four in exhaustive Encoding runs while preserving the curated default.
- Adds converter unit tests, updates technique-selection assertions, and extends Python documentation examples.
| File | Description |
|---|---|
tests/unit/scenario/garak/test_encoding.py |
Updates exhaustive technique membership and count. |
tests/unit/converter/test_upside_down_converter.py |
Tests rotation mappings, reversal, and input validation. |
tests/unit/converter/test_runic_converter.py |
Tests rune mappings, case handling, and passthrough. |
tests/unit/converter/test_ogham_converter.py |
Tests Ogham mappings, spacing, and passthrough. |
tests/unit/converter/test_mirror_converter.py |
Tests mirrored glyphs, reversal, and input validation. |
pyrit/scenario/scenarios/garak/encoding.py |
Adds four selectable encoding techniques and converter variants. |
pyrit/converter/upside_down_converter.py |
Defines rotated glyph mappings with reversed output. |
pyrit/converter/runic_converter.py |
Defines case-insensitive Elder Futhark mappings. |
pyrit/converter/ogham_converter.py |
Defines case-insensitive Ogham mappings. |
pyrit/converter/mirror_converter.py |
Defines mirrored glyph mappings with reversed output. |
pyrit/converter/_character_map.py |
Shares substitution, case handling, reversal, and validation. |
pyrit/converter/__init__.py |
Exposes all four converters through lazy exports. |
doc/code/converters/1_text_to_text_converters.py |
Adds usage examples for the new converters. |
Review effort: Balanced
| from pyrit.models import PromptDataType | ||
|
|
||
|
|
||
| class CharacterMapConverter(Converter): |
There was a problem hiding this comment.
[P2] Delete the base instead of hiding it
I agree, and I confirmed it at head d213672: the registry builds CharacterMapConverter, it returns every prompt unchanged, and the converter type catalog (REST and GUI) lists it. A mixin and a registry test would hide it, but they would keep a two-mode base with no current need: _CASE_INSENSITIVE has no user now that Runic and Ogham are LeetspeakConverter configs, both subclasses set _REVERSE_OUTPUT = True, and the module docstring still names Runic and Ogham. The base also reverses code points, not grapheme clusters (see the comment on line 58). Delete _character_map.py and make MirrorConverter and UpsideDownConverter subclass FlipConverter, each with its own table. Then nothing is registered by mistake, and no mixin or special registry test is needed.
4ced7ef to
3bbd71c
Compare
|
Reworked per the reuse-before-adding guidance: runic and ogham are now |
…cterMap) Encoding techniques Per review (reuse and compose before adding): runic and ogham are implemented as LeetspeakConverter substitution tables (no dedicated class). Mirror and UpsideDown keep dedicated converters on a shared CharacterMapConverter base because they combine a case-specific glyph map with full-string reversal, which a case-folded Leetspeak table cannot express. Co-Authored-By: Claude Opus 4.8 <[email protected]>
3bbd71c to
9050568
Compare
Richard Lundeen (richlundeen)
left a comment
There was a problem hiding this comment.
Automated review of d213672. I found three P2 and six P3 issues. Eight are inline; one P2 is a reply in the Copilot thread on _character_map.py line 22. The main change is to delete _character_map.py and build MirrorConverter and UpsideDownConverter on FlipConverter. That fixes the grapheme-cluster reversal and removes the registered no-op base. The PR also has conflicts with main (new sibling techniques and the to_ascii_equivalent hook from #4437), so it needs a rebase.
| """ | ||
| result = [self._CHAR_MAP.get(char.lower() if self._CASE_INSENSITIVE else char, char) for char in text] | ||
| if self._REVERSE_OUTPUT: | ||
| result.reverse() |
There was a problem hiding this comment.
[P2] Reverse grapheme clusters, not code points: subclass FlipConverter
_map_text reverses a list of code points. When the input has a multi-code-point cluster, the output is corrupt: UpsideDownConverter turns "go 🇺🇸" into "🇸🇺 oƃ" (a different flag), splits skin-tone modifiers from their emoji, and moves NFD accents and Devanagari vowel signs away from their base letters. MirrorConverter has the same problem, and the UpsideDownConverter docstring says non-ASCII characters only change position. FlipConverter already reverses graphemes(prompt) correctly, and the framework says to subclass or wrap an existing converter rather than copy its logic. Delete _character_map.py, make both converters subclass FlipConverter, map the characters with their own table, and return await super().convert_async(prompt=mapped, input_type=input_type). Add one test with a flag or an NFD accent. This change also removes the registered base in the Copilot thread on line 22.
| generators common online and the ``mirror`` style in elder-plinius's P4RS3LT0NGV3 repository. | ||
| """ | ||
|
|
||
| _REVERSE_OUTPUT = True |
There was a problem hiding this comment.
[P3] Keep line order in MirrorConverter
_REVERSE_OUTPUT = True reverses the whole string, so "ab\ncd" becomes "bɔ\ndɒ" and the second line comes first. Text held up to a mirror, and the Leonardo-style mirror writing in the docstring, keep their line order, so the expected output is "dɒ\nbɔ". Multi-line prompts such as templates or code are rotated instead of mirrored. UpsideDownConverter is correct to reverse the lines, because it is a 180-degree rotation. In MirrorConverter, split on \n, map and reverse each line by grapheme cluster, and join the lines again, with a two-line test. If you prefer whole-string reversal, say in the docstring that line order is reversed.
| so that after the string is reversed they end up oriented correctly. | ||
|
|
||
| Characters with no sensible mirrored glyph -- and characters that are already symmetric about a | ||
| vertical axis (e.g. ``A H I M O T U V W X Y o i l m n u v w x``, spaces, most digits) -- are left |
There was a problem hiding this comment.
[P3] Correct the symmetric-digit claim in the MirrorConverter docstring
The docstring and the table comment say most digits are symmetric and mirror to themselves. Only 0, 1 and 8 are. The digits 2, 4, 5, 6, 7 and 9 pass through unmirrored, so the docstring misdescribes the output. Also, z maps to ƹ but Z stays as it is, although Ƹ (U+01B8) exists. Say "0, 1 and 8" instead of "most digits" in both places, and add "Z": "Ƹ".
| # (https://www.unicode.org/charts/PDF/U16A0.pdf); transliteration popularized by community | ||
| # symbol-script tooling (elder-plinius's P4RS3LT0NGV3). Kept as a Leetspeak substitution table | ||
| # rather than a dedicated converter (reuse and compose before adding). | ||
| _RUNIC_SUBSTITUTIONS: dict[str, list[str]] = { |
There was a problem hiding this comment.
[P2] Credit a correct runic or ogham reading: expose the letter fold
The runic table maps several letters to one rune: c, k and q become ᚲ, v and w become ᚹ, x and z become ᛉ, and i and y become ᛁ. The ogham table maps c and k to ᚉ, and f and v to ᚃ. A target that reads each glyph by its standard value answers kokaine for cocaine or jawaskript for javascript. DecodingScorer requires the original text, so it scores that answer False and the run reports the target as resistant. This affects many default seeds: with one standard value per glyph, runic loses 17 of 17 garak_web_html_js seeds and 13 of 56 garak_slur_terms_en seeds, and ogham loses 14 of 17 and 15 of 56. Main now has the to_ascii_equivalent hook (#4437): Encoding stores its value as decoded_text, and DecodingScorer accepts it as well as the original. After the rebase, add thin RunicConverter and OghamConverter subclasses of LeetspeakConverter that use these tables and implement to_ascii_equivalent with one standard letter per glyph (for example ᚲ -> k, ᚹ -> w, ᚉ -> c, ᚃ -> f). Add a test that a folded answer scores True.
| # (https://www.unicode.org/charts/PDF/U1680.pdf); transliteration popularized by community | ||
| # symbol-script tooling (elder-plinius's P4RS3LT0NGV3). Kept as a Leetspeak substitution table | ||
| # rather than a dedicated converter (reuse and compose before adding). | ||
| _OGHAM_SUBSTITUTIONS: dict[str, list[str]] = { |
There was a problem hiding this comment.
[P3] Say that j, w and y stay Latin in the ogham table
_OGHAM_SUBSTITUTIONS has no entry for j, w or y, so "WHY just you?" becomes "WᚆY jᚒᚄᚈ yᚑᚒ?" with plain Latin letters in the output. The comment says Latin letters become Ogham characters, and the runic table maps all 26 letters, so a reader expects full coverage. Ogham has no letters for these sounds, and mapping them to ᚃ or ᚔ would add more letters that decode the same way (see the comment on the runic table). Say in the comment that j, w and y have no Ogham letter and stay Latin.
| AsciiSmuggler = ("ascii_smuggler", set[str]()) | ||
| Bifid = ("bifid", set[str]()) | ||
| ColumnarTransposition = ("columnar_transposition", set[str]()) | ||
| Runic = ("runic", set[str]()) |
There was a problem hiding this comment.
[P3] Add the new converters and techniques to the docs
These four techniques and the two new converters do not appear in the docs. The modality table in doc/code/converters/0_converters.ipynb does not list MirrorConverter or UpsideDownConverter, and the encoding technique list in doc/scanner/garak.py and its .ipynb does not list runic, ogham, mirror or upside_down, so operators who read the scanner guide cannot find them. converters.instructions.md requires the modality table update, and the sibling techniques in #4448 and #4449 updated the garak list. Re-execute 0_converters to refresh the table, and add the four techniques to the list in doc/scanner/garak.py and its .ipynb.
| print("ROT13:", await ROT13Converter().convert_async(prompt=prompt)) # type: ignore | ||
| print("Base64:", await Base64Converter().convert_async(prompt=prompt)) # type: ignore | ||
| print("Base2048:", await Base2048Converter().convert_async(prompt=prompt)) # type: ignore | ||
| print("Mirror:", await MirrorConverter().convert_async(prompt=prompt)) # type: ignore |
There was a problem hiding this comment.
[P3] Update the paired .ipynb
This .py now imports and prints MirrorConverter and UpsideDownConverter, but 1_text_to_text_converters.ipynb is not changed. The docs site renders the .ipynb, so readers do not see these examples, and the framework requires each percent-format .py to stay in sync with its .ipynb pair. Add the same imports and print lines, with their two output lines, to the .ipynb, or regenerate that notebook with jupytext --execute.
|
|
||
| async def test_runic_technique_substitutes_letters(): | ||
| """The runic Encoding technique is a LeetspeakConverter configured with the runic glyph table.""" | ||
| converter = LeetspeakConverter(custom_substitutions=_RUNIC_SUBSTITUTIONS) |
There was a problem hiding this comment.
[P3] Test the registered Encoding rows
This test builds its own LeetspeakConverter from _RUNIC_SUBSTITUTIONS, so it tests LeetspeakConverter, not the technique. If the four new rows are deleted from Encoding._converter_variants(), or the ogham row points at the runic table, all tests still pass, and selecting EncodingTechnique.Runic builds no runic attacks. The sibling techniques in #4448 and #4449 use test_*_technique_builds_registered_row tests in test_encoding.py that select the technique and inspect the raw attack's converter. Replace test_runic_technique.py and test_ogham_technique.py with one parametrized test there for Runic, Ogham, Mirror and UpsideDown: select the technique, assert <name>_raw exists with the right display_group, and check the converter output on a short input. Also replace the _MIRROR_MAP content tests in test_mirror_converter.py with one parametrized convert_async test for these pairs, so the tests use the public interface.

Adds four Unicode symbol-script / style Encoding techniques.
LeetspeakConverter(custom_substitutions=…)configs (no dedicated class; glyph tables kept as_RUNIC_SUBSTITUTIONS/_OGHAM_SUBSTITUTIONS). Sources: Unicode Runic (U+16A0) and Ogham (U+1680) blocks.CharacterMapConverterbase, because they combine a case-specific glyph map with full-string reversal (a case-folded Leetspeak table can't expressC→Ɔ,R→Я, or the reversal). Source: community symbol-script transforms (elder-plinius's P4RS3LT0NGV3).gap-1 converter series: #4441 #4442 #4443 #4444 #4445 #4446 #4447 #4448 #4449 #4450 #4451 #4452 #4454 #4455 #4456 #4457 #4458
🤖 Generated with Claude Code