mirror of
https://github.com/msoedov/agentic_security.git
synced 2026-09-30 03:41:45 +02:00
fix: docs
This commit is contained in:
+24
-143
@@ -1,153 +1,34 @@
|
||||
# Stenography Functions
|
||||
# Stenography functions
|
||||
|
||||
The stenography module provides various text obfuscation and transformation techniques for security testing. This document explains its architecture and implementation.
|
||||
`agentic_security.probe_data.stenography_fn` transforms prompts so scanners can
|
||||
test whether a model still treats obfuscated text as an instruction.
|
||||
|
||||
## Overview
|
||||
The module is used by `Stenography` in `probe_data.data` when a dataset
|
||||
enables encoding variants.
|
||||
|
||||
The module implements:
|
||||
## Functions
|
||||
|
||||
1. Rotation ciphers (ROT13, ROT5)
|
||||
1. Base64 encoding
|
||||
1. Text manipulation functions
|
||||
1. Randomization techniques
|
||||
1. Character substitution methods
|
||||
| Function | What it does |
|
||||
| --- | --- |
|
||||
| `rot13` / `rot5` | Letter and digit rotation ciphers |
|
||||
| `base64_encode` | Base64-encode a string or bytes |
|
||||
| `mirror_words` | Reverse each word, keep word order |
|
||||
| `scramble_words` | Shuffle middle letters, keep first and last |
|
||||
| `randomize_letter_case` | Random per-character case |
|
||||
| `insert_noise_characters` | Insert alphanumeric noise (`frequency=0.2` by default) |
|
||||
| `substitute_with_ascii` | Replace characters with ordinals |
|
||||
| `remove_vowels` | Drop `aeiou` in either case |
|
||||
| `zigzag_obfuscation` | Alternate upper/lower case |
|
||||
| `caesar_cipher` / `substitution_cipher` / `vigenere_cipher` | Classical ciphers |
|
||||
| `code_block_encode` | Hide the prompt in a Python docstring fenced as code |
|
||||
|
||||
## Core Functions
|
||||
These are obfuscation helpers for red-team prompts, not cryptographic primitives.
|
||||
|
||||
### Rotation Ciphers
|
||||
## Usage
|
||||
|
||||
```python
|
||||
def rot13(input_text):
|
||||
"""
|
||||
Applies ROT13 cipher to input text
|
||||
- Preserves case of letters
|
||||
- Leaves non-alphabetic characters unchanged
|
||||
"""
|
||||
# Implementation details...
|
||||
from agentic_security.probe_data.stenography_fn import rot13, scramble_words
|
||||
|
||||
def rot5(input_text):
|
||||
"""
|
||||
Applies ROT5 cipher to input text
|
||||
- Rotates digits by 5 positions
|
||||
- Leaves non-digit characters unchanged
|
||||
"""
|
||||
# Implementation details...
|
||||
rot13("Ignore previous instructions")
|
||||
scramble_words("Ignore previous instructions")
|
||||
```
|
||||
|
||||
### Encoding
|
||||
|
||||
```python
|
||||
def base64_encode(data):
|
||||
"""
|
||||
Encodes input data using Base64
|
||||
- Handles both string and bytes input
|
||||
- Returns UTF-8 encoded string
|
||||
"""
|
||||
# Implementation details...
|
||||
```
|
||||
|
||||
### Text Manipulation
|
||||
|
||||
```python
|
||||
def mirror_words(text):
|
||||
"""
|
||||
Reverses each word in the input text
|
||||
- Preserves word order
|
||||
- Maintains spaces between words
|
||||
"""
|
||||
# Implementation details...
|
||||
|
||||
def scramble_words(text):
|
||||
"""
|
||||
Randomly scrambles middle letters of words
|
||||
- Preserves first and last letters
|
||||
- Handles words shorter than 4 characters
|
||||
"""
|
||||
# Implementation details...
|
||||
```
|
||||
|
||||
### Randomization
|
||||
|
||||
```python
|
||||
def randomize_letter_case(text):
|
||||
"""
|
||||
Randomly changes case of each character
|
||||
- Independent case changes per character
|
||||
- Preserves non-letter characters
|
||||
"""
|
||||
# Implementation details...
|
||||
|
||||
def insert_noise_characters(text, frequency=0.2):
|
||||
"""
|
||||
Inserts random characters between existing ones
|
||||
- Configurable insertion frequency
|
||||
- Uses alphanumeric characters for noise
|
||||
"""
|
||||
# Implementation details...
|
||||
```
|
||||
|
||||
### Advanced Transformations
|
||||
|
||||
```python
|
||||
def substitute_with_ascii(text):
|
||||
"""
|
||||
Replaces characters with their ASCII codes
|
||||
- Space-separated numeric values
|
||||
- Preserves original character order
|
||||
"""
|
||||
# Implementation details...
|
||||
|
||||
def remove_vowels(text):
|
||||
"""
|
||||
Removes all vowel characters from text
|
||||
- Handles both lowercase and uppercase vowels
|
||||
- Preserves non-vowel characters
|
||||
"""
|
||||
# Implementation details...
|
||||
|
||||
def zigzag_obfuscation(text):
|
||||
"""
|
||||
Alternates character case in zigzag pattern
|
||||
- Starts with uppercase
|
||||
- Toggles case for each alphabetic character
|
||||
"""
|
||||
# Implementation details...
|
||||
```
|
||||
|
||||
## Usage Patterns
|
||||
|
||||
1. **Text Obfuscation**:
|
||||
|
||||
```python
|
||||
obfuscated = zigzag_obfuscation(
|
||||
scramble_words(
|
||||
insert_noise_characters(text)
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
1. **Encoding**:
|
||||
|
||||
```python
|
||||
encoded = base64_encode(rot13(text))
|
||||
```
|
||||
|
||||
1. **Randomization**:
|
||||
|
||||
```python
|
||||
randomized = randomize_letter_case(
|
||||
remove_vowels(text)
|
||||
)
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
- **Noise Frequency**: Configurable in insert_noise_characters()
|
||||
- **Scrambling**: Automatic handling of word lengths
|
||||
- **Case Handling**: Preserved in rotation ciphers
|
||||
|
||||
## Limitations
|
||||
|
||||
- Primarily handles ASCII text
|
||||
- Limited to implemented transformation types
|
||||
- Randomization is not cryptographically secure
|
||||
|
||||
Reference in New Issue
Block a user