FEAT: Add VigenereConverter - #2333
Open
diamond8658 wants to merge 2 commits into
Open
Conversation
Author
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
VigenereConverter, a classical polyalphabetic cipher converter that generalizesCaesarConverterusing a repeating keyword instead of a fixed shift. Closes #2304.Follows the existing
CaesarConverter/AtbashConverterstructure:__init__(self, *, key: str, append_description: bool = False), validates the key is non-empty and ASCII alphabetic_build_identifier()returns aComponentIdentifierwithkeyas a paramconvert_asyncencodes the prompt, with the sameappend_descriptionbehavior renderingvigenere_description.yamlvigenere_description.yamlcites Handa et al. (arXiv:2402.10601), the paper specifically covering word substitution cipher jailbreaking, rather than the CipherChat paper cited by Caesar/Atbash, since that paper doesn't cover Vigenère.Per the discussion on #2304, this does not touch
pyrit/scenario/scenarios/garak/encoding.py(garak has no corresponding probe) orFoundryTechnique(will be picked up when Foundry's converter set is refreshed separately).Tests and Documentation
New
tests/unit/converter/test_vigenere_converter.py, 13 tests covering basic encoding, case preservation, key case insensitivity, non-alphabetic passthrough (including non-ASCII alphabetic characters, which was a real bug caught during development, see note below), wraparound,append_description, and invalid key handling.Added
VigenereConverterto the existing parametrized fixtures intests/unit/converter/test_converter.pyalongside Caesar/Atbash.Verified against
tests/unit/registry/test_converter_registry.py, confirms the converter is discovered, correctly classified as non-LLM-based, and buildable through the registry.pyrit/converter/__init__.pyupdated with the import and__all__export.doc/code/converters/1_text_to_text_converters.pyupdated with a demo line. Ran withjupytext --execute --to notebook doc/code/converters/1_text_to_text_converters.py, all cells including the new one execute cleanly.Implementation note: the initial version used
str.isalpha()to detect letters, which returnsTruefor non-ASCII characters (accented letters, etc.) not present in the cipher alphabet, causing a crash. Fixed by checking ASCII letter membership explicitly. Caesar and Atbash avoid this because they usestr.translate(), which passes through unmapped characters silently.