(key: str, message: str, mode: str)
| 48 | |
| 49 | |
| 50 | def translate_message(key: str, message: str, mode: str) -> str: |
| 51 | translated = "" |
| 52 | chars_a = LETTERS |
| 53 | chars_b = key |
| 54 | |
| 55 | if mode == "decrypt": |
| 56 | chars_a, chars_b = chars_b, chars_a |
| 57 | |
| 58 | for symbol in message: |
| 59 | if symbol.upper() in chars_a: |
| 60 | sym_index = chars_a.find(symbol.upper()) |
| 61 | if symbol.isupper(): |
| 62 | translated += chars_b[sym_index].upper() |
| 63 | else: |
| 64 | translated += chars_b[sym_index].lower() |
| 65 | else: |
| 66 | translated += symbol |
| 67 | |
| 68 | return translated |
| 69 | |
| 70 | |
| 71 | def get_random_key() -> str: |
no test coverage detected