Skip to content

Commit

Permalink
Formatting and fix interfaces
Browse files Browse the repository at this point in the history
Signed-off-by: Zander Mackie <[email protected]>
  • Loading branch information
zmackie committed Feb 6, 2024
1 parent 0f56859 commit e794ab1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
44 changes: 36 additions & 8 deletions garak/probes/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def braille(text):
elif char in characterUnicodes:
if char.isdigit():
if not is_number:
is_number == True
is_number = True
output += characterUnicodes["num"]
output += characterUnicodes[char]
if is_number and char not in numberPunctuations:
Expand Down Expand Up @@ -228,7 +228,7 @@ def morse(text):
return bytes(" ".join(output), "utf-8")


def nato(text):
def nato(text: bytes) -> bytes:
nato_map = {
"A": "Alfa",
"B": "Bravo",
Expand Down Expand Up @@ -309,6 +309,27 @@ def _attempt_prestore_hook(self, attempt, seq):
return attempt


def ecoji(text: bytes) -> bytes:
from io import BytesIO

import ecoji

r = BytesIO(text)
w = BytesIO()

ecoji.encode(r, w)

return w.getvalue()


def zalgo(text: bytes) -> bytes:
from zalgolib.zalgolib import enzalgofy

zalged = enzalgofy(text=text.decode(), intensity=50)

return bytes(zalged, "utf-8")


class InjectBase64(BaseEncodingProbe, Probe):
"""Probe for susceptibility to base64 encoded injections"""

Expand Down Expand Up @@ -471,17 +492,24 @@ def __init__(self):
BaseEncodingProbe.__init__(self)
Probe.__init__(self)


class InjectEcoji(BaseEncodingProbe, Probe):
"""Probe for susceptibility to Ecoji encoding."""

encoding_name = "Ecoji"

def __init__(self):
self.encoding_funcs = [ecoji]
BaseEncodingProbe.__init__(self)
Probe.__init__(self)


class InjectZalgo(BaseEncodingProbe, Probe):
"""Probe for susceptibility to Zalgo encoding."""

encoding_name = "Zalgo"

def __init__(self):
from zalgolib import enzalgofy
from functools import partial

f = partial(enzalgofy, intensity=50) # We can tweek this if we want

self.encoding_funcs = [f]
self.encoding_funcs = [zalgo]
BaseEncodingProbe.__init__(self)
Probe.__init__(self)
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ cmd2
torch>=2.1.0
sentencepiece>=0.1.99
markdown
zalgolib>=0.2.2
zalgolib>=0.2.2
basest>=0.7.3
ecoji>=0.1.0

0 comments on commit e794ab1

Please sign in to comment.