-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecipherThis.py
More file actions
40 lines (35 loc) · 1.09 KB
/
DecipherThis.py
File metadata and controls
40 lines (35 loc) · 1.09 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
def decipher_this(string):
# count the number of words
numwords = 1
for char in string:
if char == ' ':
numwords += 1
# create a list of the words
listofwords = string.split(sep=' ')
# empty list to contain deciphered words as we manipulate them
newlistofwords = []
# print(listofwords)
for word in listofwords:
numstoppos = 0
for letter in word:
if ord(letter) < 58:
numstoppos += 1
letter = chr(int(word[:numstoppos]))
newword = letter + word[numstoppos:]
newlistofwords.append(newword)
# print(newlistofwords)
finalwordlist = []
for word in newlistofwords:
if len(word) == 1:
finalwordlist.append(word)
elif len(word) == 2:
finalwordlist.append(word)
else:
swappedword = word[0] + word[-1] + word[2:-1] + word[1]
finalwordlist.append(swappedword)
cipher = ''
for word in finalwordlist:
cipher = cipher + word + ' '
cipher = cipher.rstrip()
return cipher
return finalwordlist