Repository navigation
REFACTOR: Add shared cipher-description helper; add AffineConverter - #4456
Roman Lutz (romanlutz) wants to merge 5 commits into
Conversation
Introduces a shared maybe_render_description helper (+ common worked example) and migrates Caesar, Atbash and Morse onto it; adds the new AffineConverter (registered as an ALL-only garak Encoding technique) on the same helper. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Synchronous YAML loading on every conversion blocks the event loop and delays concurrent conversions, while the paired notebook is missing the Affine import and example.
2 open issues
What changed in this PR
Adds an Affine cipher converter to PyRIT and shares optional cipher-description rendering across several existing converters.
Changes:
- Introduces configurable Affine encoding, a description template, and a lazy public export.
- Refactors Atbash, Caesar, and Morse to use a shared description helper.
- Adds Affine to Garak’s encoding techniques, unit tests, identifier samples, and the Python documentation example.
| File | Description |
|---|---|
tests/unit/scenario/garak/test_encoding.py |
Updates technique counts and ALL-only membership. |
tests/unit/registry/converter_identifier_samples.py |
Adds valid Affine multiplier samples. |
tests/unit/converter/test_affine_converter.py |
Tests encoding, validation, and description behavior. |
pyrit/scenario/scenarios/garak/encoding.py |
Registers the Affine encoding technique. |
pyrit/datasets/converters/affine_description.yaml |
Adds Affine instructions and example framing. |
pyrit/converter/morse_converter.py |
Uses the shared description helper. |
pyrit/converter/caesar_converter.py |
Uses the shared description helper. |
pyrit/converter/atbash_converter.py |
Uses the shared description helper. |
pyrit/converter/affine_converter.py |
Implements configurable Affine encoding. |
pyrit/converter/_cipher_description.py |
Centralizes description loading and rendering. |
pyrit/converter/__init__.py |
Lazily exports AffineConverter. |
doc/code/converters/1_text_to_text_converters.py |
Adds an Affine usage example. |
Review effort: Balanced
| """ | ||
| if not append_description: | ||
| return encoded | ||
| template = SeedPrompt.from_yaml_file(pathlib.Path(CONVERTER_SEED_PROMPT_PATH) / f"{yaml_stem}_description.yaml") |
There was a problem hiding this comment.
Noted, leaving open for maintainer input. The YAML load is opt-in: append_description defaults to False, so the default conversion path never touches the template. This helper also preserves the pre-existing per-call SeedPrompt.from_yaml_file behavior that each cipher converter (Caesar/Atbash/Morse) already had before this refactor — it's consolidation, not a new hot path. Moving template loading to construction time (or an asyncio.to_thread offload across all callers) is a reasonable follow-up but is a broader change to the cipher-converter family, so I'd prefer to track it separately rather than expand this refactor PR.
| print("Morse:", await MorseConverter().convert_async(prompt=prompt)) # type: ignore | ||
| print("NATO:", await NatoConverter().convert_async(prompt=prompt)) # type: ignore | ||
| print("Caesar:", await CaesarConverter(caesar_offset=3).convert_async(prompt=prompt)) # type: ignore | ||
| print("Affine:", await AffineConverter().convert_async(prompt=prompt)) # type: ignore |
There was a problem hiding this comment.
Addressed: I added the AffineConverter import and the print("Affine:", ...) example to the paired 1_text_to_text_converters.ipynb so the two files' sources now match, following the inline-both-files approach in docs.instructions.md. I did an inline source sync (no re-execution) since this is a single non-LLM converter example; the committed cell output refresh is handled by the docs build. (Note: the notebook is also missing ColumnarTransposition and Pigpen examples that landed on main independently of this PR — out of scope here.)
Resolve garak encoding conflicts take-both (Affine + Pigpen/Disemvowel/UbbiDubbi), set EncodingTechnique ALL count to 23, bump garak doc "(23 encodings)" list, and regenerate the 0_converters.ipynb modality table to include AffineConverter. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…book Mirror the AffineConverter import and example added to the paired .py file, keeping the .py/.ipynb sources in sync per docs.instructions.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>


Part of the gap-1 converter series (splitting the esoteric cipher / encoder set into per-converter and per-base PRs). This PR introduces a shared base/helper and the converters built on it; CI-validated locally (unit + garak Encoding + identifier-contract tests).
Sibling PRs will be cross-linked once the series is open.
🤖 Generated with Claude Code
gap-1 converter series — splitting the esoteric cipher / encoder set into reviewable PRs (open each independently; they touch the same four registration files, so later ones rebase as earlier ones merge):