-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeDecode.py
More file actions
50 lines (37 loc) · 1.34 KB
/
Copy pathCodeDecode.py
File metadata and controls
50 lines (37 loc) · 1.34 KB
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
# 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
# xrsarryhwlf si a xrsoybwlf
string = input("enter the message")
words = string.split(" ")
coding =input("enter 1 for coding and 0 for decoding")
coding = True if (coding == "1") else False
if coding:
nwords=[]
for word in words:
if(len(word)>=3):
r1 = "xrs"
r2 = "wlf"
strnew = r1 + word[1:]+word[0] + r2
nwords.append(strnew)
else:
nwords.append(word[::-1])
print(" ".join(nwords))
else:
nwords=[]
for word in words:
if (len(word)>=3):
strnew = word[3:-3]
strnew = strnew[-1] + strnew[:-1]
nwords.append(strnew)
else:
nwords.append(word[::-1])
print(" ".join(nwords))