| 68 | # Function to decrypt the string |
| 69 | # from morse to english |
| 70 | def decrypt(message): |
| 71 | # extra space added at the end to access the |
| 72 | # last morse code |
| 73 | message += " " |
| 74 | |
| 75 | decipher = "" |
| 76 | citext = "" |
| 77 | for letter in message: |
| 78 | # checks for space |
| 79 | if letter != " ": |
| 80 | # counter to keep track of space |
| 81 | i = 0 |
| 82 | |
| 83 | # storing morse code of a single character |
| 84 | citext += letter |
| 85 | |
| 86 | # in case of space |
| 87 | else: |
| 88 | # if i = 1 that indicates a new character |
| 89 | i += 1 |
| 90 | |
| 91 | # if i = 2 that indicates a new word |
| 92 | if i == 2: |
| 93 | # adding space to separate words |
| 94 | decipher += " " |
| 95 | else: |
| 96 | # accessing the keys using their values (reverse of encryption) |
| 97 | decipher += list(MORSE_CODE_DICT.keys())[ |
| 98 | list(MORSE_CODE_DICT.values()).index(citext) |
| 99 | ] |
| 100 | citext = "" |
| 101 | |
| 102 | return decipher |
| 103 | |
| 104 | |
| 105 | # Hard-coded driver function to run the program |