Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions spikee/plugins/atbash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"""
Atbash Plugin

This basic plugin transforms the input text with the Atbash transformation, which swaps letters
with their counterpart on the other side of the alphabet. A becomes Z, B becomes Y, etc.,
until Y becomes B and Z becomes A.
Case of the original letter is preserved.


Usage:
spikee generate --plugins atbash
spikee generate --plugins atbash --plugin-options "atbash:hint=false"

Reference:
https://mindgard.ai/blog/bypassing-azure-ai-content-safety-guardrails

Parameters:
text (str): The input text to be transformed.
exclude_patterns (List[str], optional): Supplied by the framework. Substrings matching
these regex patterns are preserved as-is.

Returns:
str: The transformed text.
"""

from typing import List, Optional

from spikee.templates.basic_plugin import BasicPlugin
from spikee.utilities.enums import ModuleTag
from spikee.utilities.hinting import ModuleDescriptionHint, ModuleOptionsHint
from spikee.utilities.modules import parse_options


class AtbashPlugin(BasicPlugin):
_ALPHA_UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
_ALPHA_LOWER = "abcdefghijklmnopqrstuvwxyz"
ATBASH_TABLE = str.maketrans(
_ALPHA_UPPER + _ALPHA_LOWER,
_ALPHA_UPPER[::-1] + _ALPHA_LOWER[::-1],
)

def get_description(self) -> ModuleDescriptionHint:
return [ModuleTag.ENCODING], "Applies Atbash cipher with optional hint."

def get_available_option_values(self) -> ModuleOptionsHint:
return [
"hint=true",
"hint=true/false (hint=true prepends the literal string 'atbash ' to the full output)",
], False

def plugin_transform(self, text: str, plugin_option: str = "") -> str:
"""
Transforms the input text using the Atbash cipher.

Args:
text (str): The input text (or chunk thereof).
plugin_option (str, optional): Plugin options string.

Returns:
str: The Atbash-transformed text.
"""
return self._apply_atbash(text)

def transform(
self,
text: str,
exclude_patterns: Optional[List[str]] = None,
plugin_option: str = "",
) -> str:
"""
Overrides BasicPlugin.transform solely to apply the optional hint prefix.

Args:
text (str): The full input text.
exclude_patterns (List[str], optional): Passed through to BasicPlugin for exclusion handling.
plugin_option (str, optional): Plugin options string.

Returns:
str: The transformed text, with optional 'atbash ' prefix.
"""
opts = parse_options(plugin_option)
hint = opts.get("hint", "true").lower() == "true"

transformed = super().transform(
text, exclude_patterns=exclude_patterns, plugin_option=plugin_option
)

return "atbash " + transformed if hint else transformed

def _apply_atbash(self, text: str) -> str:
return text.translate(self.ATBASH_TABLE)
39 changes: 39 additions & 0 deletions spikee/plugins/binary_in_ascii.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
BinaryInAscii Plugin

Encodes text as space-separated ASCII/Unicode binary codepoint values (8 bits each).
"Spikee plugin" > "01010011 01110000 01101001 01101011 01100101 01100101 00100000
01110000 01101100 01110101 01100111 01101001 01101110"

Usage:
spikee generate --plugins binary_in_ascii

Parameters:
text (str): Input string to transform.
exclude_patterns (List[str], optional): Supplied by the framework. Substrings matching
these regex patterns are preserved as-is.

Returns:
str: Space-separated 8-bit binary codepoint values.
"""

from spikee.templates.basic_plugin import BasicPlugin
from spikee.utilities.enums import ModuleTag
from spikee.utilities.hinting import ModuleDescriptionHint, ModuleOptionsHint


class BinaryInAsciiPlugin(BasicPlugin):
def get_description(self) -> ModuleDescriptionHint:
return [
ModuleTag.ENCODING
], "Encodes text as 8-bit binary codepoint representation."

def get_available_option_values(self) -> ModuleOptionsHint:
return [], False

def plugin_transform(self, text: str, plugin_option: str = "") -> str:
return self._apply_binary(text)

def _apply_binary(self, text: str) -> str:
"""Return space-separated 8-bit binary Unicode codepoints for each character."""
return " ".join(f"{ord(c):08b}" for c in text)
48 changes: 15 additions & 33 deletions spikee/plugins/ceasar.py → spikee/plugins/caesar.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
"""
Caesar Cipher Plugin

This plugin transforms the input text using a simple Caesar cipher encryption.
This plugin transforms the input text using a simple Caesar cipher.
By default, it shifts letters forward by a 3 number of positions in the alphabet.
"Hello" with shift=3 > "Khoor"
Use shift=13 for rot13, which is its own reverse.

Usage:
spikee generate --plugins caesar
spikee generate --plugins caesar --plugin-options "caesar:shift=5"

Parameters:
text (str): The input text to be transformed.
shift (int): The number of positions to shift each letter (default is 3).

Returns:
str: The encrypted text using the Caesar cipher.
"""

from typing import List, Optional

from spikee.templates.plugin import Plugin
from spikee.utilities.hinting import ModuleDescriptionHint, ModuleOptionsHint
from spikee.templates.basic_plugin import BasicPlugin
from spikee.utilities.enums import ModuleTag
from spikee.utilities.hinting import ModuleDescriptionHint, ModuleOptionsHint


class CeasarPlugin(Plugin):
class CaesarPlugin(BasicPlugin):
DEFAULT_SHIFT = 3

def get_description(self) -> ModuleDescriptionHint:
return [ModuleTag.ENCODING], "Transforms text using a Caesar cipher encryption."

def get_available_option_values(self) -> ModuleOptionsHint:
"""Return supported attack options; Tuple[options (default is first), llm_required]"""
return [
"shift=3",
"shift=N (1-26)",
], False
return ["shift=3", "shift=N (1-26)", "shift=13 for rot13"], False

def plugin_transform(self, content: str, plugin_option: str = "") -> str:
shift = self._parse_shift_option(plugin_option)
return self.caesar_cipher(content, shift)

def _parse_shift_option(self, option: str) -> int:
"""Parse shift option string like 'shift=3' and return the number."""
Expand All @@ -46,42 +48,22 @@ def _parse_shift_option(self, option: str) -> int:
pass
return self.DEFAULT_SHIFT

def caesar_cipher(self, text: str, shift: int = 3) -> str:
def caesar_cipher(self, content: str, shift: int = 3) -> str:
"""
Encrypts the input text using a Caesar cipher with the given shift value.

Args:
text (str): The input text.
content (str): The input text.
shift (int): The number of positions to shift each letter.

Returns:
str: The encrypted text.
"""
result = []
for char in text:
for char in content:
if char.isalpha():
shift_base = ord("A") if char.isupper() else ord("a")
result.append(chr((ord(char) - shift_base + shift) % 26 + shift_base))
else:
result.append(char)
return "".join(result)

def transform(
self,
content: str,
exclude_patterns: Optional[List[str]] = None,
plugin_option: str = ""
) -> str:
"""
Transforms the input text using the Caesar cipher.

Args:
text (str): The input text.
shift (int): The number of positions to shift each letter (default is 3).

Returns:
str: The encrypted text using the Caesar cipher.
"""
shift = self._parse_shift_option(plugin_option)

return self.caesar_cipher(content, shift)
69 changes: 69 additions & 0 deletions spikee/plugins/decimal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""
DecimalEncoder Plugin

Encodes text as space-separated ASCII/Unicode decimal codepoint values.
"Spikee plugin" > "decimal 83 112 105 107 101 101 32 112 108 117 103 105 110"

Usage:
spikee generate --plugins decimal
spikee generate --plugins decimal --plugin-options "decimal:hint=false"

Parameters:
text (str): Input string to transform.
exclude_patterns (List[str], optional): Supplied by the framework. Substrings matching
these regex patterns are preserved as-is.

Returns:
str: Space-separated decimal codepoint values, prefixed with 'decimal ' by default.
"""

from typing import List, Optional

from spikee.templates.basic_plugin import BasicPlugin
from spikee.utilities.enums import ModuleTag
from spikee.utilities.hinting import ModuleDescriptionHint, ModuleOptionsHint
from spikee.utilities.modules import parse_options


class DecimalEncoderPlugin(BasicPlugin):
def get_description(self) -> ModuleDescriptionHint:
return [ModuleTag.ENCODING], "Encodes text as decimal codepoint representation."

def get_available_option_values(self) -> ModuleOptionsHint:
return [
"hint=true",
"hint=true/false (hint=true prepends the literal string 'decimal ' to the full output)",
], False

def plugin_transform(self, content: str, plugin_option: str = "") -> str:
return self._apply_decimal(content)

def transform(
self,
content: str,
exclude_patterns: Optional[List[str]] = None,
plugin_option: str = "",
) -> str:
"""
Overrides BasicPlugin.transform solely to apply the optional hint prefix.

Args:
content (str): The full input text.
exclude_patterns (List[str], optional): Passed through to BasicPlugin for exclusion handling.
plugin_option (str, optional): Plugin options string.

Returns:
str: The transformed text, with optional 'decimal ' prefix.
"""
opts = parse_options(plugin_option)
hint = opts.get("hint", "true").lower() == "true"

transformed = super().transform(
content, exclude_patterns=exclude_patterns, plugin_option=plugin_option
)

return "decimal " + transformed if hint else transformed

def _apply_decimal(self, content: str) -> str:
"""Return space-separated decimal Unicode codepoints for each character."""
return " ".join(str(ord(c)) for c in content)
69 changes: 69 additions & 0 deletions spikee/plugins/octal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""
OctalEncoder Plugin

Encodes text as space-separated ASCII/Unicode octal codepoint values.
"Spikee plugin" > "octal 123 160 151 153 145 145 40 160 154 165 147 151 156"

Usage:
spikee generate --plugins octal
spikee generate --plugins octal --plugin-options "octal:hint=false"

Parameters:
text (str): Input string to transform.
exclude_patterns (List[str], optional): Supplied by the framework. Substrings matching
these regex patterns are preserved as-is.

Returns:
str: Space-separated octal codepoint values, prefixed with 'octal ' by default.
"""

from typing import List, Optional

from spikee.templates.basic_plugin import BasicPlugin
from spikee.utilities.enums import ModuleTag
from spikee.utilities.hinting import ModuleDescriptionHint, ModuleOptionsHint
from spikee.utilities.modules import parse_options


class OctalEncoderPlugin(BasicPlugin):
def get_description(self) -> ModuleDescriptionHint:
return [ModuleTag.ENCODING], "Encodes text as octal codepoint representation."

def get_available_option_values(self) -> ModuleOptionsHint:
return [
"hint=true",
"hint=true/false (hint=true prepends the literal string 'octal ' to the full output)",
], False

def plugin_transform(self, content: str, plugin_option: str = "") -> str:
return self._apply_octal(content)

def transform(
self,
content: str,
exclude_patterns: Optional[List[str]] = None,
plugin_option: str = "",
) -> str:
"""
Overrides BasicPlugin.transform solely to apply the optional hint prefix.

Args:
content (str): The full input text.
exclude_patterns (List[str], optional): Passed through to BasicPlugin for exclusion handling.
plugin_option (str, optional): Plugin options string.

Returns:
str: The transformed text, with optional 'octal ' prefix.
"""
opts = parse_options(plugin_option)
hint = opts.get("hint", "true").lower() == "true"

transformed = super().transform(
content, exclude_patterns=exclude_patterns, plugin_option=plugin_option
)

return "octal " + transformed if hint else transformed

def _apply_octal(self, content: str) -> str:
"""Return space-separated octal Unicode codepoints for each character."""
return " ".join(f"{ord(c):o}" for c in content)
Loading