-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecode_the_message_2325.py
More file actions
32 lines (25 loc) · 959 Bytes
/
decode_the_message_2325.py
File metadata and controls
32 lines (25 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Solution:
def decodeMessage(self, key: str, message: str) -> str:
n = len(key)
i = 0
current_char = 0
cipher_text_mapping = dict()
while i <= n - 1:
if key[i] != ' ' and key[i] not in cipher_text_mapping:
cipher_text_mapping[key[i]] = chr(current_char + 97)
current_char += 1
i += 1
result = []
for character in message:
if character == " ":
result.append(" ")
else:
result.append(cipher_text_mapping[character])
return "".join(result)
sol = Solution()
key = "the quick brown fox jumps over the lazy dog"
message = "vkbs bs t suepuv"
print(f"{key = } | {message = }| {sol.decodeMessage(key, message) = }")
key = "eljuxhpwnyrdgtqkviszcfmabo"
message = "zwx hnfx lqantp mnoeius ycgk vcnjrdb"
print(f"{key = } | {message = }| {sol.decodeMessage(key, message) = }")