>>> decrypt_message(4545, 'VL}p MM{I}p~{HL}Gp{vp pFsH}pxMpyxIx JHL O}F{~pvuOvF{FuF' ... '{xIp~{HL}Gi') 'The affine cipher is a type of monoalphabetic substitution cipher.'
(key: int, message: str)
| 54 | |
| 55 | |
| 56 | def decrypt_message(key: int, message: str) -> str: |
| 57 | """ |
| 58 | >>> decrypt_message(4545, 'VL}p MM{I}p~{HL}Gp{vp pFsH}pxMpyxIx JHL O}F{~pvuOvF{FuF' |
| 59 | ... '{xIp~{HL}Gi') |
| 60 | 'The affine cipher is a type of monoalphabetic substitution cipher.' |
| 61 | """ |
| 62 | key_a, key_b = divmod(key, len(SYMBOLS)) |
| 63 | check_keys(key_a, key_b, "decrypt") |
| 64 | plain_text = "" |
| 65 | mod_inverse_of_key_a = cryptomath.find_mod_inverse(key_a, len(SYMBOLS)) |
| 66 | for symbol in message: |
| 67 | if symbol in SYMBOLS: |
| 68 | sym_index = SYMBOLS.find(symbol) |
| 69 | plain_text += SYMBOLS[ |
| 70 | (sym_index - key_b) * mod_inverse_of_key_a % len(SYMBOLS) |
| 71 | ] |
| 72 | else: |
| 73 | plain_text += symbol |
| 74 | return plain_text |
| 75 | |
| 76 | |
| 77 | def get_random_key() -> int: |
no test coverage detected