decrypt_message =============== Decrypts a trifid_cipher encrypted message. PARAMETERS ---------- * `message`: The message you want to decrypt. * `alphabet` (optional): The characters used for the cipher. * `period` (optional): The number of chara
(
message: str, alphabet: str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.", period: int = 5
)
| 167 | |
| 168 | |
| 169 | def decrypt_message( |
| 170 | message: str, alphabet: str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.", period: int = 5 |
| 171 | ) -> str: |
| 172 | """ |
| 173 | decrypt_message |
| 174 | =============== |
| 175 | |
| 176 | Decrypts a trifid_cipher encrypted message. |
| 177 | |
| 178 | PARAMETERS |
| 179 | ---------- |
| 180 | |
| 181 | * `message`: The message you want to decrypt. |
| 182 | * `alphabet` (optional): The characters used for the cipher. |
| 183 | * `period` (optional): The number of characters used in grouping when it |
| 184 | was encrypted. |
| 185 | |
| 186 | >>> decrypt_message('BCDGBQY') |
| 187 | 'IAMABOY' |
| 188 | |
| 189 | Decrypting with your own alphabet and period |
| 190 | |
| 191 | >>> decrypt_message('FMJFVOISSUFTFPUFEQQC','FELIXMARDSTBCGHJKNOPQUVWYZ+',5) |
| 192 | 'AIDETOILECIELTAIDERA' |
| 193 | """ |
| 194 | message, alphabet, character_to_number, number_to_character = __prepare( |
| 195 | message, alphabet |
| 196 | ) |
| 197 | |
| 198 | decrypted_numeric = [] |
| 199 | for i in range(0, len(message), period): |
| 200 | a, b, c = __decrypt_part(message[i : i + period], character_to_number) |
| 201 | |
| 202 | for j in range(len(a)): |
| 203 | decrypted_numeric.append(a[j] + b[j] + c[j]) |
| 204 | |
| 205 | return "".join(number_to_character[each] for each in decrypted_numeric) |
| 206 | |
| 207 | |
| 208 | if __name__ == "__main__": |
no test coverage detected