diff --git a/pyrit/scenario/scenarios/garak/encoding.py b/pyrit/scenario/scenarios/garak/encoding.py index a427f02596..48e21a987d 100644 --- a/pyrit/scenario/scenarios/garak/encoding.py +++ b/pyrit/scenario/scenarios/garak/encoding.py @@ -51,6 +51,40 @@ from pyrit.scenario.core.scenario_technique import ScenarioTechnique from pyrit.score import DecodingScorer, TrueFalseScorer +# Baconian cipher (Francis Bacon, 1605): each letter maps to a 5-symbol a/b group; see +# https://en.wikipedia.org/wiki/Bacon%27s_cipher . Framing classical ciphers as an LLM jailbreak +# vector: CipherChat (Yuan et al., 2023, arXiv:2308.06463). +# Kept as a Leetspeak substitution table rather than a dedicated converter (reuse and compose +# before adding). +_BACONIAN_SUBSTITUTIONS: dict[str, list[str]] = { + "a": ["aaaaa"], + "b": ["aaaab"], + "c": ["aaaba"], + "d": ["aaabb"], + "e": ["aabaa"], + "f": ["aabab"], + "g": ["aabba"], + "h": ["aabbb"], + "i": ["abaaa"], + "j": ["abaaa"], + "k": ["abaab"], + "l": ["ababa"], + "m": ["ababb"], + "n": ["abbaa"], + "o": ["abbab"], + "p": ["abbba"], + "q": ["abbbb"], + "r": ["baaaa"], + "s": ["baaab"], + "t": ["baaba"], + "u": ["baabb"], + "v": ["baabb"], + "w": ["babaa"], + "x": ["babab"], + "y": ["babba"], + "z": ["babbb"], +} + class EncodingDatasetConfiguration(DatasetAttackConfiguration): """ @@ -129,6 +163,7 @@ class EncodingTechnique(ScenarioTechnique): AsciiSmuggler = ("ascii_smuggler", set[str]()) Bifid = ("bifid", set[str]()) ColumnarTransposition = ("columnar_transposition", set[str]()) + Baconian = ("baconian", set[str]()) @classmethod def get_aggregate_tags(cls) -> set[str]: @@ -317,6 +352,7 @@ def _converter_variants() -> list[tuple[list[Converter], str, str]]: ([AsciiSmugglerConverter()], "ascii_smuggler", "ascii_smuggler"), ([BifidConverter()], "bifid", "bifid"), ([ColumnarTranspositionConverter(key="ZEBRAS")], "columnar_transposition", "columnar_transposition"), + ([LeetspeakConverter(custom_substitutions=_BACONIAN_SUBSTITUTIONS)], "baconian", "baconian"), ] # These are the same as Garak encoding attacks diff --git a/tests/unit/scenario/garak/test_baconian_technique.py b/tests/unit/scenario/garak/test_baconian_technique.py new file mode 100644 index 0000000000..98631be80f --- /dev/null +++ b/tests/unit/scenario/garak/test_baconian_technique.py @@ -0,0 +1,12 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT license. + +from pyrit.converter import LeetspeakConverter +from pyrit.scenario.scenarios.garak.encoding import _BACONIAN_SUBSTITUTIONS + + +async def test_baconian_technique_encodes_letters(): + """The baconian Encoding technique is a LeetspeakConverter configured with the Baconian a/b table.""" + converter = LeetspeakConverter(custom_substitutions=_BACONIAN_SUBSTITUTIONS) + result = await converter.convert_async(prompt="ab") + assert result.output_text == _BACONIAN_SUBSTITUTIONS["a"][0] + _BACONIAN_SUBSTITUTIONS["b"][0] diff --git a/tests/unit/scenario/garak/test_encoding.py b/tests/unit/scenario/garak/test_encoding.py index 5e4bd78538..38f3eea500 100644 --- a/tests/unit/scenario/garak/test_encoding.py +++ b/tests/unit/scenario/garak/test_encoding.py @@ -253,13 +253,14 @@ def test_default_aggregate_curates_representative_subset(self): } all_names = {t.value for t in EncodingTechnique.get_all_techniques()} assert default_names < all_names - assert len(all_names) == 19 + assert len(all_names) == 20 # The niche/lossy schemes stay ALL-only. assert all_names - default_names == { "braille", "ecoji", "zalgo", "ascii_smuggler", + "baconian", "bifid", "columnar_transposition", }