Decrypt a ciphertext message encrypted with Fractionated Morse Cipher. Args: ciphertext: The ciphertext message to decrypt. key: The decryption key. Returns: The decrypted plaintext message. Example: >>> decrypt_fractionated_morse("ESOAVVLJRSSTRX","Roun
(ciphertext: str, key: str)
| 127 | |
| 128 | |
| 129 | def decrypt_fractionated_morse(ciphertext: str, key: str) -> str: |
| 130 | """Decrypt a ciphertext message encrypted with Fractionated Morse Cipher. |
| 131 | |
| 132 | Args: |
| 133 | ciphertext: The ciphertext message to decrypt. |
| 134 | key: The decryption key. |
| 135 | |
| 136 | Returns: |
| 137 | The decrypted plaintext message. |
| 138 | |
| 139 | Example: |
| 140 | >>> decrypt_fractionated_morse("ESOAVVLJRSSTRX","Roundtable") |
| 141 | 'DEFEND THE EAST' |
| 142 | """ |
| 143 | key = key.upper() + string.ascii_uppercase |
| 144 | key = "".join(sorted(set(key), key=key.find)) |
| 145 | |
| 146 | inverse_fractionated_morse_dict = dict(zip(key, MORSE_COMBINATIONS)) |
| 147 | morse_code = "".join( |
| 148 | [inverse_fractionated_morse_dict.get(letter, "") for letter in ciphertext] |
| 149 | ) |
| 150 | decrypted_text = "".join( |
| 151 | [REVERSE_DICT[code] for code in morse_code.split("x")] |
| 152 | ).strip() |
| 153 | return decrypted_text |
| 154 | |
| 155 | |
| 156 | if __name__ == "__main__": |
no test coverage detected