-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hitman-code-language.py
40 lines (33 loc) · 996 Bytes
/
Hitman-code-language.py
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
33
34
35
36
37
38
39
40
import random as rd
msg = input("Enter msg : ")
lmsg = msg.split(" ")
choice = input('Enter "code" for Coding & "decode" for Decoding : ').lower()
# Encoding Part
if (choice == "code"):
encode_word = []
for i in lmsg:
if (len(i) >= 3):
r_char = [rd.choice('abcdefghijklmnopqrstuvwxyz') for _ in range(3)]
random_char = ''.join(r_char)
new_word = random_char + i[1:] + i[:1] + random_char
encode_word.append(new_word)
else:
new_word = i[::-1]
encode_word.append(new_word)
coded_word = " ".join(encode_word)
print(coded_word)
# Decoding Part
elif (choice == "decode"):
decode_word = []
for i in lmsg:
if (len(i) >= 3):
random_remove = i[3:-3]
new_word = random_remove[-1] + random_remove[:-1]
decode_word.append(new_word)
else:
new_word = i[::-1]
decode_word.append(new_word)
decoded_word = " ".join(decode_word)
print(decoded_word)
else:
print("Enter Valid Option : \"code\" or \"decode\"")