>>> encrypt_message(4545, 'The affine cipher is a type of monoalphabetic ' ... 'substitution cipher.') 'VL}p MM{I}p~{HL}Gp{vp pFsH}pxMpyxIx JHL O}F{~pvuOvF{FuF{xIp~{HL}Gi'
(key: int, message: str)
| 36 | |
| 37 | |
| 38 | def encrypt_message(key: int, message: str) -> str: |
| 39 | """ |
| 40 | >>> encrypt_message(4545, 'The affine cipher is a type of monoalphabetic ' |
| 41 | ... 'substitution cipher.') |
| 42 | 'VL}p MM{I}p~{HL}Gp{vp pFsH}pxMpyxIx JHL O}F{~pvuOvF{FuF{xIp~{HL}Gi' |
| 43 | """ |
| 44 | key_a, key_b = divmod(key, len(SYMBOLS)) |
| 45 | check_keys(key_a, key_b, "encrypt") |
| 46 | cipher_text = "" |
| 47 | for symbol in message: |
| 48 | if symbol in SYMBOLS: |
| 49 | sym_index = SYMBOLS.find(symbol) |
| 50 | cipher_text += SYMBOLS[(sym_index * key_a + key_b) % len(SYMBOLS)] |
| 51 | else: |
| 52 | cipher_text += symbol |
| 53 | return cipher_text |
| 54 | |
| 55 | |
| 56 | def decrypt_message(key: int, message: str) -> str: |
no test coverage detected