Deciphers a message given a cipher map :param message: Message to decipher :param cipher_map: Dictionary mapping to use :return: Deciphered string >>> cipher_map = create_cipher_map('Goodbye!!') >>> decipher(encipher('Hello World!!', cipher_map), cipher_map) 'HELLO WOR
(message: str, cipher_map: dict[str, str])
| 58 | |
| 59 | |
| 60 | def decipher(message: str, cipher_map: dict[str, str]) -> str: |
| 61 | """ |
| 62 | Deciphers a message given a cipher map |
| 63 | |
| 64 | :param message: Message to decipher |
| 65 | :param cipher_map: Dictionary mapping to use |
| 66 | :return: Deciphered string |
| 67 | |
| 68 | >>> cipher_map = create_cipher_map('Goodbye!!') |
| 69 | >>> decipher(encipher('Hello World!!', cipher_map), cipher_map) |
| 70 | 'HELLO WORLD!!' |
| 71 | """ |
| 72 | # Reverse our cipher mappings |
| 73 | rev_cipher_map = {v: k for k, v in cipher_map.items()} |
| 74 | return "".join(rev_cipher_map.get(ch, ch) for ch in message.upper()) |
| 75 | |
| 76 | |
| 77 | def main() -> None: |