Repository navigation
FEAT: Add pigpen Encoding technique via LeetspeakConverter - #4446
Roman Lutz (romanlutz) wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The published notebook lacks the Pigpen import, example, and rendered output, leaving readers without the new example and violating the requirement to keep paired documentation files synchronized.
1 open issue
What changed in this PR
Adds PigpenConverter to PyRIT’s text-obfuscation converters and integrates it into the garak Encoding scenario.
Changes:
- Implements a case-insensitive Unicode approximation of the Pigpen cipher.
- Exports the converter and registers it as an ALL-only encoding technique.
- Adds converter tests, updates scenario expectations, and adds a Python documentation example.
| File | Description |
|---|---|
tests/unit/scenario/garak/test_encoding.py |
Updates technique counts and ALL-only expectations. |
tests/unit/converter/test_pigpen_converter.py |
Tests mappings, case handling, passthrough, and input validation. |
pyrit/scenario/scenarios/garak/encoding.py |
Registers the Pigpen encoding technique. |
pyrit/converter/pigpen_converter.py |
Implements the Unicode Pigpen converter. |
pyrit/converter/__init__.py |
Adds the public lazy export. |
doc/code/converters/1_text_to_text_converters.py |
Adds a Pigpen conversion example. |
Review effort: Balanced
| 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("Pigpen:", await PigpenConverter().convert_async(prompt=prompt)) # type: ignore |
There was a problem hiding this comment.
Withdrawn: this earlier suggestion to drop the named converter in favor of configuring an existing one no longer applies. Named converters are welcome; see the current review.
Richard Lundeen (richlundeen)
left a comment
There was a problem hiding this comment.
Source review of this head: one P1 and three P3 findings, inline. The notebook pairing is already covered by the open thread on 1_text_to_text_converters.py:87.
| # Box Drawings fragments for the A-I tic-tac-toe grid. Each character's strokes | ||
| # mark the grid lines that border the corresponding cell (reading left-to-right, | ||
| # top-to-bottom), e.g. the centre cell E has all four borders -> "┼". | ||
| _GRID = ( |
There was a problem hiding this comment.
[P1] Draw each Pigpen letter as the lines that surround its cell
The table picks each glyph by its Unicode stroke directions (U+250C is DOWN AND RIGHT, the directions of A's right and bottom borders), but when drawn, each glyph is the opposite shape in the cited key (line 16). a gives ┌, which is the key's I, and i gives ┘, which is the key's A. c/g, b/h and d/f swap in the same way, and e gives a cross ┼ where the key draws a closed box. In the key, the X grid has S at the top, T left, U right and V bottom, so s △ reads as V, u ▽ as S and v ◁ as U; only t ▷ matches. The Encoding scenario tells the target that the text is "pigpen encoded", so a target that knows the key reads cat (┐┌▷) as git, and DecodingScorer records a non-decode. Use A ┘, B ⊔, C └, D ⊐, E □, F ⊏, G ┐, H ⊓, I ┌ and S ▽, T ▷, U ◁, V △, and keep the combining dot for J-R and W-Z. Write the table as one class-level dict literal. Update EXPECTED, the docstring examples and triangle order (lines 24, 27-28, 65), and the block-range test (the new A-I glyphs include Mathematical Operators characters U+228F-U+2294). Add one test that pins a corner letter to the key, for example 'a' -> '┘'. After this change, generate the notebook output for the thread on 1_text_to_text_converters.py:87.
There was a problem hiding this comment.
[P1] This still applies at this head. The rework moved the same glyph table to _PIGPEN_SUBSTITUTIONS in pyrit/scenario/scenarios/garak/encoding.py (lines 59-86), so the thread's file is gone but the cause is not. a still gives ┌ (the key's I), e gives a cross ┼ instead of a closed box, and s/u/v still read as V/S/U; 24 of 26 letters do not match the cited key. Two of the four decode templates still tell the target that the text is pigpen encoded, so cat is sent as ┐┌▷, which reads git, and DecodingScorer compares against cat. Use the table from the original comment (A ┘, B ⊔, C └, D ⊐, E □, F ⊏, G ┐, H ⊓, I ┌; S ▽, T ▷, U ◁, V △; combining dot for J-R and W-Z) and add one test with an independently written expected glyph, for example a -> ┘.
|
|
||
| The exact fragment/triangle assignment is one documented convention among several | ||
| (Pigpen has many layout variants and no canonical Unicode form); the mapping is | ||
| lossless and reversible at the code-point level. Conversion is case-insensitive. |
There was a problem hiding this comment.
[P3] Remove the lossless and reversible claim
A reader who decodes the output can get a different prompt: Hello and hello encode to the same string, a followed by U+0307 encodes like j, and a literal ┌ in the input reads back as a. Replace the sentence with "The 26 letters map to distinct glyphs; case is not preserved."
| LeetSpeak = ("leet_speak", {"default"}) | ||
| AsciiSmuggler = ("ascii_smuggler", set[str]()) | ||
| Bifid = ("bifid", set[str]()) | ||
| Pigpen = ("pigpen", set[str]()) |
There was a problem hiding this comment.
[P3] List Pigpen where the Encoding techniques are listed
The comment at lines 111-112 names the ALL-only schemes as Braille, Ecoji, Zalgo and AsciiSmuggler (Bifid is already missing). doc/scanner/garak.py:139-141 and its .ipynb pair say "Available techniques (18 encodings)" and end the list with Bifid. This change makes 19, so a reader cannot find Pigpen there. Add Bifid and Pigpen to the ALL-only list in the comment, and update doc/scanner/garak.py and doc/scanner/garak.ipynb to "19 encodings" with Pigpen added.
There was a problem hiding this comment.
[P3] This still applies at this head, with one correction to the count. After the merge of main, EncodingTechnique has 20 techniques (test_encoding.py:256 now asserts 20), not 19. doc/scanner/garak.py:139 and its .ipynb pair still say 18 encodings and list neither ColumnarTransposition nor Pigpen, and the ALL-only comment at encoding.py:145-146 still omits Bifid, ColumnarTransposition and Pigpen. Update both doc formats to 20 encodings with both names, and complete the comment.
| assert result.output_text == expected | ||
|
|
||
|
|
||
| async def test_pigpen_converter_all_glyphs_distinct(): |
There was a problem hiding this comment.
[P3] Remove the self-checking test and the redundant tests
test_pigpen_converter_all_glyphs_distinct reads only the test's EXPECTED dict and never calls the converter, so it still passes if two letters collide in the converter. Make it convert each letter through PigpenConverter and assert 26 distinct outputs, or delete it, because the per-letter test already pins each glyph. Also delete known_word (:65), mixed_case_word (:78), space_preserved (:93) and supported_types (:135). They repeat the per-letter and case parametrizations, the passthrough test that already contains spaces, and class declarations rather than behavior. Fewer tests also means fewer edits when the table is corrected.
There was a problem hiding this comment.
[P3] The old converter tests are gone, so this request is done as written. The replacement test has a related gap: test_pigpen_technique.py builds its own LeetspeakConverter from the private _PIGPEN_SUBSTITUTIONS and computes the expected text from the same table, so it tests LeetspeakConverter rather than the technique. With the pigpen row removed from Encoding._converter_variants and the a glyph replaced, both changed test files still pass (33 passed). Replace it with one test that selects EncodingTechnique.Pigpen through the existing test_encoding.py fixtures and asserts a fixed, independently written glyph string, for example the corrected encoding of cat. That same test can serve as the regression test requested in the glyph-table thread, so only one new test is needed.
8d31701 to
5d03e25
Compare
|
Reworked per your suggestion: dropped |
Per review (reuse and compose before adding): keep the pigpen technique but implement it as LeetspeakConverter(custom_substitutions=<pigpen glyph table>) instead of a dedicated PigpenConverter class. The documented Pigpen key is retained as _PIGPEN_SUBSTITUTIONS. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
5d03e25 to
194134a
Compare

Adds the pigpen Encoding technique via an existing converter (reuse before adding):
LeetspeakConverter(custom_substitutions=_PIGPEN_SUBSTITUTIONS), with the documented Pigpen glyph table retained as that constant. Keeps the named technique and a focused test.Pigpen — geometric monoalphabetic substitution (the Freemason's / Masonic cipher; Wikipedia). Classical ciphers as a jailbreak vector: CipherChat, Yuan et al., arXiv:2308.06463.
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