-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSecret_Code_Language.py
50 lines (33 loc) · 1.12 KB
/
Secret_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
41
42
43
44
45
46
47
48
49
50
# First tell the Program that you want to code or decode the message
a=int(input("Press 1 for Coding and Press 2 for Decoding: "))
# a can be either 1 or 2 otherwise raise an error
if not (a==1 or a==2):
raise ValueError("The input Could be either 1 for coding or 2 for decoding")
# For coding take message as input you want to code
if a==1:
m=input("Message: ")
# We will split the string using space
k=m.split(" ") #it is in list as each word of string
v=[]
for i in k:
if len(i)<=3:
c=i[::-1] #just will be tsuj
else:
c="hjk"+i[1:]+i[0]+"bvs"
v.append(c)
b=(" ".join(v))
print("Coded Message: ",b)
# Decoding The messages
if a==2:
m=input("Coded Message: ")
# We will split the string using space
k=m.split(" ") #it is in list as each word of string
v=[]
for i in k:
if len(i)<=3:
c=i[::-1] #just will be tsuj
else:
c=i[-4]+i[3:-4]
v.append(c)
b=(" ".join(v))
print("Decoded Message: ",b)