Skip to content

REFACTOR: Add shared cipher-description helper; add AffineConverter - #4456

Draft
Roman Lutz (romanlutz) wants to merge 3 commits into
microsoft:mainfrom
romanlutz:gap1-cipher-description
Draft

Roman Lutz (romanlutz) wants to merge 3 commits into
microsoft:mainfrom
romanlutz:gap1-cipher-description

Conversation

@romanlutz

@romanlutz Roman Lutz (romanlutz) commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

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):

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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")
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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants