-
Notifications
You must be signed in to change notification settings - Fork 9
/
secret_code.py
43 lines (37 loc) · 1.2 KB
/
secret_code.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
# Write a python program to translate a message into secret code language. Use the rules below to translate normal English into secret code language
# Coding:
# if the word contains atleast 3 characters, remove the first letter and append it at the end
# now append three random characters at the starting and the end
# else:
# simply reverse the string
# Decoding:
# if the word contains less than 3 characters, reverse it
# else:
# remove 3 random characters from start and end. Now remove the last letter and append it to the beginning
# Your program should ask whether you want to code or decode
st = input("Enter message")
words = st.split(" ")
coding = input("1 for Coding or 0 for Decoding")
coding = True if (coding=="1") else False
print(coding)
if(coding):
nwords = []
for word in words:
if(len(word)>=3):
r1 = "dsf"
r2 = "jkr"
stnew = r1+ word[1:] + word[0] + r2
nwords.append(stnew)
else:
nwords.append(word[::-1])
print(" ".join(nwords))
else:
nwords = []
for word in words:
if(len(word)>=3):
stnew = word[3:-3]
stnew = stnew[-1] + stnew[:-1]
nwords.append(stnew)
else:
nwords.append(word[::-1])
print(" ".join(nwords))