Source code for pyrit.prompt_converter.emoji_converter

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

import random

from pyrit.models import PromptDataType
from pyrit.prompt_converter import PromptConverter, ConverterResult


[docs] class EmojiConverter(PromptConverter): emoji_dict = { "a": ["πŸ…", "πŸ…°οΈ", "πŸ„°"], "b": ["πŸ…‘", "πŸ…±οΈ", "πŸ„±"], "c": ["πŸ…’", "πŸ…²", "πŸ„²"], "d": ["πŸ…“", "πŸ…³", "πŸ„³"], "e": ["πŸ…”", "πŸ…΄", "πŸ„΄"], "f": ["πŸ…•", "πŸ…΅", "πŸ„΅"], "g": ["πŸ…–", "πŸ…Ά", "πŸ„Ά"], "h": ["πŸ…—", "πŸ…·", "πŸ„·"], "i": ["πŸ…˜", "πŸ…Έ", "πŸ„Έ"], "j": ["πŸ…™", "πŸ…Ή", "πŸ„Ή"], "k": ["πŸ…š", "πŸ…Ί", "πŸ„Ί"], "l": ["πŸ…›", "πŸ…»", "πŸ„»"], "m": ["πŸ…œ", "πŸ…Ό", "πŸ„Ό"], "n": ["πŸ…", "πŸ…½", "πŸ„½"], "o": ["πŸ…ž", "πŸ…ΎοΈ", "πŸ„Ύ"], "p": ["πŸ…Ÿ", "πŸ…ΏοΈ", "πŸ„Ώ"], "q": ["πŸ… ", "πŸ†€", "πŸ…€"], "r": ["πŸ…‘", "πŸ†", "πŸ…"], "s": ["πŸ…’", "πŸ†‚", "πŸ…‚"], "t": ["πŸ…£", "πŸ†ƒ", "πŸ…ƒ"], "u": ["πŸ…€", "πŸ†„", "πŸ…„"], "v": ["πŸ…₯", "πŸ†…", "πŸ……"], "w": ["πŸ…¦", "πŸ††", "πŸ…†"], "x": ["πŸ…§", "πŸ†‡", "πŸ…‡"], "y": ["πŸ…¨", "πŸ†ˆ", "πŸ…ˆ"], "z": ["πŸ…©", "πŸ†‰", "πŸ…‰"], }
[docs] async def convert_async(self, *, prompt: str, input_type: PromptDataType = "text") -> ConverterResult: """ Converts English text to randomly chosen circle or square character emojis. Inspired by https://github.com/BASI-LABS/parseltongue/blob/main/src/utils.ts """ if not self.input_supported(input_type): raise ValueError("Input type not supported") prompt = prompt.lower() result = [] for char in prompt: if char in EmojiConverter.emoji_dict: result.append(random.choice(EmojiConverter.emoji_dict[char])) else: result.append(char) ret_text = "".join(result) return ConverterResult(output_text=ret_text, output_type="text")
[docs] def input_supported(self, input_type: PromptDataType) -> bool: return input_type == "text"