def _morse()

in pyrit/prompt_converter/morse_converter.py [0:0]


    def _morse(self, text: str) -> str:
        text_clean = " ".join([line.strip() for line in str.splitlines(text)])
        morse_mapping = {
            "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": "--..",
            "0": "-----",
            "1": ".----",
            "2": "..---",
            "3": "...--",
            "4": "....-",
            "5": ".....",
            "6": "-....",
            "7": "--...",
            "8": "---..",
            "9": "----.",
            "'": ".----.",
            '"': ".-..-.",
            ":": "---...",
            "@": ".--.-.",
            ",": "--..--",
            ".": ".-.-.-",
            "!": "-.-.--",
            "?": "..--..",
            "-": "-....-",
            "/": "-..-.",
            "+": ".-.-.",
            "=": "-...-",
            "(": "-.--.",
            ")": "-.--.-",
            "&": ".-...",
            " ": "/",
        }
        extended_mapping = {
            "%": "------..-.-----",
            "À": ".--.-",
            "Å": ".--.-",
            "Ä": ".-.-",
            "Ą": ".-.-",
            " Æ": ".-.-",
            "Ć": "-.-..",
            "Ĉ": "-.-..",
            "Ç": "-.-..",
            "Ĥ": "----",
            "Š": "----",
            "Đ": "..-..",
            "É": "..-..",
            "Ę": "..-..",
            "Ð": "..--.",
            "È": ".-..-",
            "Ł": ".-..-",
            "Ĝ": "--.-.",
            "Ĵ": ".---.",
            "Ń": "--.--",
            "Ñ": "--.--",
            "Ó": "---.",
            "Ö": "---.",
            "Ø": "---.",
            "Ś": "...-...",
            "Ŝ": "...-.",
            "Þ": ".--..",
            "Ü": "..--",
            "Ŭ": "..--",
            "Ź": "--..-.",
            "Ż": "--..-",
        }
        EXTENDED_CHAR_SUPPORT = True
        supported_charset = "".join(morse_mapping.keys())
        if EXTENDED_CHAR_SUPPORT:
            supported_charset += "".join(extended_mapping.keys())
            morse_mapping = {**morse_mapping, **extended_mapping}
        error_char = "........"
        return " ".join(
            [morse_mapping[char] if char in supported_charset else error_char for char in text_clean.upper()]
        )