@@ -59,6 +59,7 @@ def get_continue():
59
59
if another== ' n' :
60
60
# program ends when user type n
61
61
print (" Thanks for using the program, goodbye!" )
62
+ quit () # program ends
62
63
63
64
# This function is used to encrypt
64
65
# English to morse code
@@ -81,30 +82,41 @@ def encode(message):
81
82
82
83
83
84
# This function is used to decrypt
84
- # Morse code to English
85
+ # Morse code to Englishdef decrypt(message):
85
86
def decode (message ):
86
- decipher = ' '
87
- codetext = ' '
88
- for code in message:
89
- # checking for space
90
- if (code != ' ' ):
91
- # to track spaces
92
- a = 0
93
- # for storing morse code of a single character
94
- codetext += code
95
- # for space
87
+ message += ' '
88
+ decipher = ' '
89
+ code_text = ' '
90
+ for letter in message:
91
+
92
+ # checks for space
93
+ if (letter != ' ' ):
94
+
95
+ # counter to keep track of space
96
+ i = 0
97
+
98
+ # storing morse code of a single character
99
+ code_text += letter
100
+
101
+ # in case of space
96
102
else :
97
- # if a = 1 signifies a new character
98
- a += 1
99
- # if a = 2 signifies a new word
100
- if a == 2 :
101
- # adding space to separate words
103
+ # if i = 1 that indicates a new character
104
+ i += 1
105
+
106
+ # if i = 2 that indicates a new word
107
+ if i == 2 :
108
+
109
+ # adding space to separate words
102
110
decipher += ' '
103
111
else :
104
- # to access the keys using value
105
- decipher += list (dictionary.keys())[list (dictionary.values()).index(codetext)]
106
- codetext = ' '
112
+
113
+ # accessing the keys using their values (reverse of encryption)
114
+ decipher += list (dictionary.keys())[list (dictionary
115
+ .values()).index(code_text)]
116
+ code_text = ' '
117
+
107
118
return decipher
119
+
108
120
# main funtion
109
121
def main ():
110
122
print_intro() # this funtion executes in first
@@ -114,8 +126,7 @@ def main():
114
126
115
127
# program begins from here
116
128
if __name__ == ' __main__' :
117
- main() # executes main funtion
118
-
129
+ main() # executes main funtion
119
130
120
131
```
121
132
## Output of the program
0 commit comments