Converters

Converters#

Converters are used to transform prompts before sending them to the target.

This can be useful for a variety of reasons, such as encoding the prompt in a different format, or adding additional information to the prompt. For example, you might want to convert a prompt to base64 before sending it to the target, or add a prefix to the prompt to indicate that it is a question.

Simple Converter Example#

Converters can be used to perform these types of transformations. Here is a simple program that uses Rot13Converter converter, RandomCapitalLettersConverter, and AsciiArtConverter.

from pyrit.common import IN_MEMORY, initialize_pyrit
from pyrit.prompt_converter import (
    AsciiArtConverter,
    BinaryConverter,
    FirstLetterConverter,
    RandomCapitalLettersConverter,
    ROT13Converter,
)

initialize_pyrit(memory_db_type=IN_MEMORY)

prompt = "tell me how to cut down a tree"


print(await ROT13Converter().convert_tokens_async(prompt=prompt))  # type: ignore
print(await RandomCapitalLettersConverter(percentage=25.0).convert_tokens_async(prompt=prompt))  # type: ignore
print(await AsciiArtConverter().convert_tokens_async(prompt=prompt))  # type: ignore
print(await BinaryConverter().convert_tokens_async(prompt=prompt))  # type: ignore
print(await FirstLetterConverter().convert_tokens_async(prompt=prompt))  # type: ignore
text: gryy zr ubj gb phg qbja n gerr
text: tell me how tO cuT down A trEe
text:       _____                    _____                    _____            _____                    _____                    _____                            _____                   _______                   _____                        _____                   _______                           _____                    _____                _____                            _____                   _______                   _____                    _____                            _____                        _____                    _____                    _____                    _____          
     /\    \                  /\    \                  /\    \          /\    \                  /\    \                  /\    \                          /\    \                 /::\    \                 /\    \                      /\    \                 /::\    \                         /\    \                  /\    \              /\    \                          /\    \                 /::\    \                 /\    \                  /\    \                          /\    \                      /\    \                  /\    \                  /\    \                  /\    \         
    /::\    \                /::\    \                /::\____\        /::\____\                /::\____\                /::\    \                        /::\____\               /::::\    \               /::\____\                    /::\    \               /::::\    \                       /::\    \                /::\____\            /::\    \                        /::\    \               /::::\    \               /::\____\                /::\____\                        /::\    \                    /::\    \                /::\    \                /::\    \                /::\    \        
    \:::\    \              /::::\    \              /:::/    /       /:::/    /               /::::|   |               /::::\    \                      /:::/    /              /::::::\    \             /:::/    /                    \:::\    \             /::::::\    \                     /::::\    \              /:::/    /            \:::\    \                      /::::\    \             /::::::\    \             /:::/    /               /::::|   |                       /::::\    \                   \:::\    \              /::::\    \              /::::\    \              /::::\    \       
     \:::\    \            /::::::\    \            /:::/    /       /:::/    /               /:::::|   |              /::::::\    \                    /:::/    /              /::::::::\    \           /:::/   _/___                   \:::\    \           /::::::::\    \                   /::::::\    \            /:::/    /              \:::\    \                    /::::::\    \           /::::::::\    \           /:::/   _/___            /:::::|   |                      /::::::\    \                   \:::\    \            /::::::\    \            /::::::\    \            /::::::\    \      
      \:::\    \          /:::/\:::\    \          /:::/    /       /:::/    /               /::::::|   |             /:::/\:::\    \                  /:::/    /              /:::/~~\:::\    \         /:::/   /\    \                   \:::\    \         /:::/~~\:::\    \                 /:::/\:::\    \          /:::/    /                \:::\    \                  /:::/\:::\    \         /:::/~~\:::\    \         /:::/   /\    \          /::::::|   |                     /:::/\:::\    \                   \:::\    \          /:::/\:::\    \          /:::/\:::\    \          /:::/\:::\    \     
       \:::\    \        /:::/__\:::\    \        /:::/    /       /:::/    /               /:::/|::|   |            /:::/__\:::\    \                /:::/____/              /:::/    \:::\    \       /:::/   /::\____\                   \:::\    \       /:::/    \:::\    \               /:::/  \:::\    \        /:::/    /                  \:::\    \                /:::/  \:::\    \       /:::/    \:::\    \       /:::/   /::\____\        /:::/|::|   |                    /:::/__\:::\    \                   \:::\    \        /:::/__\:::\    \        /:::/__\:::\    \        /:::/__\:::\    \    
       /::::\    \      /::::\   \:::\    \      /:::/    /       /:::/    /               /:::/ |::|   |           /::::\   \:::\    \              /::::\    \             /:::/    / \:::\    \     /:::/   /:::/    /                   /::::\    \     /:::/    / \:::\    \             /:::/    \:::\    \      /:::/    /                   /::::\    \              /:::/    \:::\    \     /:::/    / \:::\    \     /:::/   /:::/    /       /:::/ |::|   |                   /::::\   \:::\    \                  /::::\    \      /::::\   \:::\    \      /::::\   \:::\    \      /::::\   \:::\    \   
      /::::::\    \    /::::::\   \:::\    \    /:::/    /       /:::/    /               /:::/  |::|___|______    /::::::\   \:::\    \            /::::::\    \   _____   /:::/____/   \:::\____\   /:::/   /:::/   _/___                /::::::\    \   /:::/____/   \:::\____\           /:::/    / \:::\    \    /:::/    /      _____        /::::::\    \            /:::/    / \:::\    \   /:::/____/   \:::\____\   /:::/   /:::/   _/___    /:::/  |::|   | _____            /::::::\   \:::\    \                /::::::\    \    /::::::\   \:::\    \    /::::::\   \:::\    \    /::::::\   \:::\    \  
     /:::/\:::\    \  /:::/\:::\   \:::\    \  /:::/    /       /:::/    /               /:::/   |::::::::\    \  /:::/\:::\   \:::\    \          /:::/\:::\    \ /\    \ |:::|    |     |:::|    | /:::/___/:::/   /\    \              /:::/\:::\    \ |:::|    |     |:::|    |         /:::/    /   \:::\    \  /:::/____/      /\    \      /:::/\:::\    \          /:::/    /   \:::\ ___\ |:::|    |     |:::|    | /:::/___/:::/   /\    \  /:::/   |::|   |/\    \          /:::/\:::\   \:::\    \              /:::/\:::\    \  /:::/\:::\   \:::\____\  /:::/\:::\   \:::\    \  /:::/\:::\   \:::\    \ 
    /:::/  \:::\____\/:::/__\:::\   \:::\____\/:::/____/       /:::/____/               /:::/    |:::::::::\____\/:::/__\:::\   \:::\____\        /:::/  \:::\    /::\____\|:::|____|     |:::|    ||:::|   /:::/   /::\____\            /:::/  \:::\____\|:::|____|     |:::|    |        /:::/____/     \:::\____\|:::|    /      /::\____\    /:::/  \:::\____\        /:::/____/     \:::|    ||:::|____|     |:::|    ||:::|   /:::/   /::\____\/:: /    |::|   /::\____\        /:::/  \:::\   \:::\____\            /:::/  \:::\____\/:::/  \:::\   \:::|    |/:::/__\:::\   \:::\____\/:::/__\:::\   \:::\____\
   /:::/    \::/    /\:::\   \:::\   \::/    /\:::\    \       \:::\    \               \::/    / ~~~~~/:::/    /\:::\   \:::\   \::/    /        \::/    \:::\  /:::/    / \:::\    \   /:::/    / |:::|__/:::/   /:::/    /           /:::/    \::/    / \:::\    \   /:::/    /         \:::\    \      \::/    /|:::|____\     /:::/    /   /:::/    \::/    /        \:::\    \     /:::|____| \:::\    \   /:::/    / |:::|__/:::/   /:::/    /\::/    /|::|  /:::/    /        \::/    \:::\  /:::/    /           /:::/    \::/    /\::/   |::::\  /:::|____|\:::\   \:::\   \::/    /\:::\   \:::\   \::/    /
  /:::/    / \/____/  \:::\   \:::\   \/____/  \:::\    \       \:::\    \               \/____/      /:::/    /  \:::\   \:::\   \/____/          \/____/ \:::\/:::/    /   \:::\    \ /:::/    /   \:::\/:::/   /:::/    /           /:::/    / \/____/   \:::\    \ /:::/    /           \:::\    \      \/____/  \:::\    \   /:::/    /   /:::/    / \/____/          \:::\    \   /:::/    /   \:::\    \ /:::/    /   \:::\/:::/   /:::/    /  \/____/ |::| /:::/    /          \/____/ \:::\/:::/    /           /:::/    / \/____/  \/____|:::::\/:::/    /  \:::\   \:::\   \/____/  \:::\   \:::\   \/____/ 
 /:::/    /            \:::\   \:::\    \       \:::\    \       \:::\    \                          /:::/    /    \:::\   \:::\    \                       \::::::/    /     \:::\    /:::/    /     \::::::/   /:::/    /           /:::/    /             \:::\    /:::/    /             \:::\    \               \:::\    \ /:::/    /   /:::/    /                    \:::\    \ /:::/    /     \:::\    /:::/    /     \::::::/   /:::/    /           |::|/:::/    /                    \::::::/    /           /:::/    /                 |:::::::::/    /    \:::\   \:::\    \       \:::\   \:::\    \     
/:::/    /              \:::\   \:::\____\       \:::\    \       \:::\    \                        /:::/    /      \:::\   \:::\____\                       \::::/    /       \:::\__/:::/    /       \::::/___/:::/    /           /:::/    /               \:::\__/:::/    /               \:::\    \               \:::\    /:::/    /   /:::/    /                      \:::\    /:::/    /       \:::\__/:::/    /       \::::/___/:::/    /            |::::::/    /                      \::::/    /           /:::/    /                  |::|\::::/    /      \:::\   \:::\____\       \:::\   \:::\____\    
\::/    /                \:::\   \::/    /        \:::\    \       \:::\    \                      /:::/    /        \:::\   \::/    /                       /:::/    /         \::::::::/    /         \:::\__/:::/    /            \::/    /                 \::::::::/    /                 \:::\    \               \:::\__/:::/    /    \::/    /                        \:::\  /:::/    /         \::::::::/    /         \:::\__/:::/    /             |:::::/    /                       /:::/    /            \::/    /                   |::| \::/____/        \:::\   \::/    /        \:::\   \::/    /    
 \/____/                  \:::\   \/____/          \:::\    \       \:::\    \                    /:::/    /          \:::\   \/____/                       /:::/    /           \::::::/    /           \::::::::/    /              \/____/                   \::::::/    /                   \:::\    \               \::::::::/    /      \/____/                          \:::\/:::/    /           \::::::/    /           \::::::::/    /              |::::/    /                       /:::/    /              \/____/                    |::|  ~|               \:::\   \/____/          \:::\   \/____/     
                           \:::\    \               \:::\    \       \:::\    \                  /:::/    /            \:::\    \                          /:::/    /             \::::/    /             \::::::/    /                                          \::::/    /                     \:::\    \               \::::::/    /                                         \::::::/    /             \::::/    /             \::::::/    /               /:::/    /                       /:::/    /                                          |::|   |                \:::\    \               \:::\    \         
                            \:::\____\               \:::\____\       \:::\____\                /:::/    /              \:::\____\                        /:::/    /               \::/____/               \::::/    /                                            \::/____/                       \:::\____\               \::::/    /                                           \::::/    /               \::/____/               \::::/    /               /:::/    /                       /:::/    /                                           \::|   |                 \:::\____\               \:::\____\        
                             \::/    /                \::/    /        \::/    /                \::/    /                \::/    /                        \::/    /                 ~~                      \::/____/                                              ~~                              \::/    /                \::/____/                                             \::/____/                 ~~                      \::/____/                \::/    /                        \::/    /                                             \:|   |                  \::/    /                \::/    /        
                              \/____/                  \/____/          \/____/                  \/____/                  \/____/                          \/____/                                           ~~                                                                                     \/____/                  ~~                                                    ~~                                                ~~                       \/____/                          \/____/                                               \|___|                   \/____/                  \/____/         
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

text: 0000000001110100 0000000001100101 0000000001101100 0000000001101100 0000000000100000 0000000001101101 0000000001100101 0000000000100000 0000000001101000 0000000001101111 0000000001110111 0000000000100000 0000000001110100 0000000001101111 0000000000100000 0000000001100011 0000000001110101 0000000001110100 0000000000100000 0000000001100100 0000000001101111 0000000001110111 0000000001101110 0000000000100000 0000000001100001 0000000000100000 0000000001110100 0000000001110010 0000000001100101 0000000001100101
text: t m h t c d a t
# Close connection
from pyrit.memory import CentralMemory

memory = CentralMemory.get_memory_instance()
memory.dispose_engine()