Encrypt a plaintext message using Fractionated Morse Cipher. Args: plaintext: The plaintext message to encrypt. key: The encryption key. Returns: The encrypted ciphertext. Example: >>> encrypt_fractionated_morse("defend the east","Roundtable") '
(plaintext: str, key: str)
| 93 | |
| 94 | |
| 95 | def encrypt_fractionated_morse(plaintext: str, key: str) -> str: |
| 96 | """Encrypt a plaintext message using Fractionated Morse Cipher. |
| 97 | |
| 98 | Args: |
| 99 | plaintext: The plaintext message to encrypt. |
| 100 | key: The encryption key. |
| 101 | |
| 102 | Returns: |
| 103 | The encrypted ciphertext. |
| 104 | |
| 105 | Example: |
| 106 | >>> encrypt_fractionated_morse("defend the east","Roundtable") |
| 107 | 'ESOAVVLJRSSTRX' |
| 108 | |
| 109 | """ |
| 110 | morse_code = encode_to_morse(plaintext) |
| 111 | key = key.upper() + string.ascii_uppercase |
| 112 | key = "".join(sorted(set(key), key=key.find)) |
| 113 | |
| 114 | # Ensure morse_code length is a multiple of 3 |
| 115 | padding_length = 3 - (len(morse_code) % 3) |
| 116 | morse_code += "x" * padding_length |
| 117 | |
| 118 | fractionated_morse_dict = {v: k for k, v in zip(key, MORSE_COMBINATIONS)} |
| 119 | fractionated_morse_dict["xxx"] = "" |
| 120 | encrypted_text = "".join( |
| 121 | [ |
| 122 | fractionated_morse_dict[morse_code[i : i + 3]] |
| 123 | for i in range(0, len(morse_code), 3) |
| 124 | ] |
| 125 | ) |
| 126 | return encrypted_text |
| 127 | |
| 128 | |
| 129 | def decrypt_fractionated_morse(ciphertext: str, key: str) -> str: |
no test coverage detected