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

Function encipher

ciphers/simple_keyword_cypher.py:46–57  ·  view source on GitHub ↗

Enciphers a message given a cipher map. :param message: Message to encipher :param cipher_map: Cipher map :return: enciphered string >>> encipher('Hello World!!', create_cipher_map('Goodbye!!')) 'CYJJM VMQJB!!'

(message: str, cipher_map: dict[str, str])

Source from the content-addressed store, hash-verified

44
45
46def encipher(message: str, cipher_map: dict[str, str]) -> str:
47 """
48 Enciphers a message given a cipher map.
49
50 :param message: Message to encipher
51 :param cipher_map: Cipher map
52 :return: enciphered string
53
54 >>> encipher('Hello World!!', create_cipher_map('Goodbye!!'))
55 'CYJJM VMQJB!!'
56 """
57 return "".join(cipher_map.get(ch, ch) for ch in message.upper())
58
59
60def decipher(message: str, cipher_map: dict[str, str]) -> str:

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected