Skip to content

FEAT: Add ColumnarTranspositionConverter (classical transposition cipher) - #4327

Merged
Roman Lutz (romanlutz) merged 7 commits into
microsoft:mainfrom
romanlutz:claude/g1-columnar-transposition-ebba96
Nov 19, 2026
Merged

Roman Lutz (romanlutz) merged 7 commits into
microsoft:mainfrom
romanlutz:claude/g1-columnar-transposition-ebba96

Conversation

@romanlutz

Copy link
Copy Markdown
Contributor

Description

Adds ColumnarTranspositionConverter — the classical columnar transposition cipher — to PyRIT's converter catalog, filling a gap in the classical-cipher converters (joining CaesarConverter and VigenereConverter).

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 configurable key (validated non-empty, ASCII-alphabetic; ordering case-insensitive, repeated letters broken by original left-to-right position via a stable sort). _build_identifier exposes key.
  • 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 using key="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

  • Standard library only — no new dependency.
  • References cited in the class docstring: Wikipedia "Transposition cipher" (public domain) and CipherChat (arXiv:2308.06463), which frames classical ciphers as a jailbreak technique.

Tests

  • pytest tests/unit/converter/test_columnar_transposition_converter.py — 13/13 passing.
  • All pre-commit hooks pass (ruff format/check, ty type-check, keyword-only, _async suffix, public-import).

🤖 Generated with Claude Code

…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 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 16, 2026 01:11

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

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

@varunj-msft varunj-msft 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.

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.

…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 <noreply@anthropic.com>
… 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 <noreply@anthropic.com>
…ansposition-ebba96

# Conflicts:
#	doc/code/converters/1_text_to_text_converters.py
#	pyrit/scenario/scenarios/garak/encoding.py
#	tests/unit/scenario/garak/test_encoding.py
…bba96' into claude/g1-columnar-transposition-ebba96
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Nov 19, 2026
Merged via the queue into microsoft:main with commit e1bcfaf Nov 19, 2026
64 of 65 checks passed
@romanlutz
Roman Lutz (romanlutz) deleted the claude/g1-columnar-transposition-ebba96 branch November 19, 2026 22:59
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.

3 participants