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

Function translate_message

ciphers/simple_substitution_cipher.py:50–68  ·  view source on GitHub ↗
(key: str, message: str, mode: str)

Source from the content-addressed store, hash-verified

48
49
50def 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
71def get_random_key() -> str:

Callers 2

encrypt_messageFunction · 0.70
decrypt_messageFunction · 0.70

Calls 1

findMethod · 0.45

Tested by

no test coverage detected