Repository navigation
FEAT: Add ColumnarTranspositionConverter (classical transposition cipher) - #4327
Roman Lutz (romanlutz) wants to merge 4 commits into
Conversation
…her) Implements the standard incomplete-columns columnar transposition cipher as a PyRIT converter: plaintext is written row-wise under a keyword and columns are read out in the alphabetical order of the keyword's letters. Pure permutation over all characters, no padding. Registered as an encoding technique in the garak Encoding scenario. Stdlib only. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The new technique breaks aggregate test expectations, and its decoding prompts omit the keyword and incomplete-column convention needed for reliable decoding.
2 open issues
What changed in this PR
Adds a configurable columnar transposition cipher to PyRIT’s converter catalog and integrates it into the Garak encoding scenario.
Changes:
- Implements case-insensitive keyword ordering and padding-free transposition that preserves all input characters.
- Adds a lazy public export and an ALL-only encoding technique using
ZEBRAS. - Adds 13 unit tests covering known output, edge cases, identifiers, and validation.
| File | Description |
|---|---|
tests/unit/converter/test_columnar_transposition_converter.py |
Tests cipher behavior and input validation. |
pyrit/scenario/scenarios/garak/encoding.py |
Registers the ALL-only technique and converter variant. |
pyrit/converter/columnar_transposition_converter.py |
Implements the keyword-based transposition converter. |
pyrit/converter/__init__.py |
Exposes the converter through lazy imports. |
Review effort: Balanced
| Zalgo = ("zalgo", set[str]()) | ||
| LeetSpeak = ("leet_speak", {"default"}) | ||
| AsciiSmuggler = ("ascii_smuggler", set[str]()) | ||
| ColumnarTransposition = ("columnar_transposition", set[str]()) |
There was a problem hiding this comment.
Fixed in 68795f2: test_encoding.py now asserts 18 techniques and includes columnar_transposition in the ALL-only set, with DEFAULT expectations unchanged.
| ([ZalgoConverter()], "zalgo", "zalgo"), | ||
| ([LeetspeakConverter()], "leet_speak", "leet_speak"), | ||
| ([AsciiSmugglerConverter()], "ascii_smuggler", "ascii_smuggler"), | ||
| ([ColumnarTranspositionConverter(key="ZEBRAS")], "columnar_transposition", "columnar_transposition"), |
There was a problem hiding this comment.
Addressed in a2c55a9: the converter now exposes decode_prompt_description (built from its key), and the Encoding scenario feeds that into the decode templates only — disclosing the ZEBRAS keyword and incomplete-column read order — while the raw variant, technique slug, selection, and display grouping still key off the plain columnar_transposition name. Added a test asserting decode prompts disclose the key and the raw variant does not.
varunj-msft
left a comment
There was a problem hiding this comment.
Looks like the new converter still needs a mention in the converter notebooks and the 0_converters modality table (test_all_converters_are_documented fails), and the "(17 encodings)" list in doc/scanner/garak.py might want a refresh too.
| Raises: | ||
| ValueError: If ``key`` is empty or contains non-alphabetic characters. | ||
| """ | ||
| if not key or not all(char in string.ascii_letters for char in key): |
There was a problem hiding this comment.
Since this rejects the test_value placeholder, test_build_instance_from_converter fails in CI — maybe add an entry next to VigenereConverter in the overrides map in test_converter_service.py?
There was a problem hiding this comment.
Done in 68795f2 — added "ColumnarTranspositionConverter": {"key": "testvalue"} next to VigenereConverter in the overrides map.
…rter - test_converter_service: add key override so the auto-instantiation test passes an alphabetic key (mirrors VigenereConverter). - test_encoding: bump ALL-aggregate count to 18 and add columnar_transposition to the ALL-only (non-default) set. - doc notebook: document ColumnarTranspositionConverter in the text-to-text converters notebook so the documentation test passes. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ansposition-ebba96
… prompts A keyed transposition cannot be reversed from the encoding name alone, so decode prompts that only name the scheme make decoding failures ambiguous. ColumnarTranspositionConverter now exposes a decode_prompt_description built from its key, and the Encoding scenario feeds that description into the decode templates (AskToDecodeConverter) while leaving the raw variant, technique slug, selection, and display grouping unchanged. Addresses PR review feedback. Co-Authored-By: Claude Opus 4.8 <[email protected]>


Description
Adds
ColumnarTranspositionConverter— the classical columnar transposition cipher — to PyRIT's converter catalog, filling a gap in the classical-cipher converters (joiningCaesarConverterandVigenereConverter).Plaintext is written row-wise into a grid whose number of columns equals the length of a keyword; the ciphertext is produced by reading the columns out in the alphabetical order of the keyword's letters. This is the standard incomplete-columns variant: the final row may be partially filled, columns can be of unequal length, and no padding characters are added. It is a pure permutation over all characters (spaces, digits, and punctuation included), so it is fully reversible given the keyword and message length.
Worked example (canonical Wikipedia vector): with
key="ZEBRAS",WEAREDISCOVEREDFLEEATONCE→EVLNACDTESEAROFODEECWIREE.Changes
pyrit/converter/columnar_transposition_converter.py— new converter with a configurablekey(validated non-empty, ASCII-alphabetic; ordering case-insensitive, repeated letters broken by original left-to-right position via a stable sort)._build_identifierexposeskey.pyrit/converter/__init__.py— lazy export registration.pyrit/scenario/scenarios/garak/encoding.py— registered as an ALL-only encoding technique (columnar_transposition) with a_converter_variants()row usingkey="ZEBRAS".tests/unit/converter/test_columnar_transposition_converter.py— 13 unit tests, including the known Wikipedia vector, case-insensitivity, repeated-key-letter stability, permutation invariance, space/punctuation preservation, degenerate cases, identifier params, and input/key validation guards.Notes
Tests
pytest tests/unit/converter/test_columnar_transposition_converter.py— 13/13 passing._asyncsuffix, public-import).🤖 Generated with Claude Code