MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / decrypt_fractionated_morse

Function decrypt_fractionated_morse

ciphers/fractionated_morse_cipher.py:129–153  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

127
128
129def 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
156if __name__ == "__main__":

Callers 1

Calls 2

splitMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected