MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / decipher

Function decipher

ciphers/simple_keyword_cypher.py:60–74  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

58
59
60def 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
77def main() -> None:

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected