-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecret_code_language.py
More file actions
41 lines (40 loc) · 963 Bytes
/
Copy pathsecret_code_language.py
File metadata and controls
41 lines (40 loc) · 963 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
33
34
35
36
37
38
39
40
41
import random
import string
print("\t\tSecret Code Language")
a=input("Enter 1 for encoding and 2 for decoding:")
if(a=='1'):
msg=input("Enter your message to encode:")
w=msg.split(" ")
new=[]
for i in w:
if(len(i)<3):
c=list(i)
c.reverse()
x="".join(c)
else:
r=''.join(random.choices(string.ascii_letters,k=3))
c=list(i)
c.extend(c[0])
c.pop(0)
c.insert(0,r)
x="".join(c)
new.append(x)
print(" ".join(new))
else:
msg=input("Enter code to decode:")
w=msg.split(" ")
new=[]
for i in w:
if(len(i)<3):
c=list(i)
c.reverse()
x="".join(c)
else:
r=len(i)-4
c=list(i)
del c[:3]
c.insert(0,c[r])
c.pop(r+1)
x="".join(c)
new.append(x)
print(" ".join(new))