Skip to content

Commit 6e486df

Browse files
authored
Merge pull request sanscript-tech#254 from Tejas1510/moorse
Added the code for Moorse Code Generator
2 parents 76cd02f + 395d22f commit 6e486df

File tree

6 files changed

+159
-0
lines changed

6 files changed

+159
-0
lines changed

Python/MoorseCodeGenerator/Readme.MD

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Moorse Code Generator
2+
3+
## Introduction
4+
```
5+
Moorse Code generated is based on the standard moorse code chart provided by wikipedia explaining the concept of encryption and decryption.
6+
The code takes a english word as input and give the converted moorse code as output --> Encryption
7+
Moreover it also convert the given moorse code to english word --> Decryption
8+
```
9+
### The Moorse Code Chart used in the
10+
11+
![endpoint](https://github.com/Tejas1510/hacking-tools-scripts/blob/moorse/Python/MoorseCodeGenerator/images/image1.png)
12+
13+
## How to use the code
14+
```
15+
1. Download the given code
16+
17+
2. Run the moorse.py file
18+
3. you will ask to enter either choice 1 or 2
19+
4. If you select choice 1 then you will enter english word and moorse code will be generated
20+
5. choice 2 will be reverse of the above
21+
```
22+
## Output
23+
24+
![endpoint](https://github.com/Tejas1510/hacking-tools-scripts/blob/moorse/Python/MoorseCodeGenerator/images/image2.png)
25+
26+
![built with love](https://forthebadge.com/images/badges/built-with-love.svg)
27+
28+
Check out my Github profile [Tejas1510!](https://github.com/Tejas1510)

Python/MoorseCodeGenerator/decrypt.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
def decrypt(msg, MORSE_CODE_DICTIONARY):
2+
li1 = list(MORSE_CODE_DICTIONARY.keys())
3+
li2 = list(MORSE_CODE_DICTIONARY.values())
4+
dic = dict()
5+
for i, j in zip(li1, li2):
6+
dic[j] = i
7+
if msg[len(msg) - 1] == " ":
8+
msg = msg[:-1]
9+
wordlist = msg.split(" / ")
10+
LetterList = list()
11+
DecryptedMessage = list()
12+
for i in wordlist:
13+
Word = ""
14+
LetterList = i.split(" ")
15+
for j in LetterList:
16+
if j not in li2:
17+
print(j)
18+
DecryptedMessage.clear()
19+
DecryptedMessage.append('INVALID MORSE CODE!!')
20+
return DecryptedMessage
21+
Word = Word + dic[j]
22+
DecryptedMessage.append(Word)
23+
Word = ""
24+
return DecryptedMessage

Python/MoorseCodeGenerator/encrypt.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
import winsound
3+
import time
4+
5+
# here i have used the standard moorse code chart provided by wikipedia and other website
6+
# you can change if you wish to do so
7+
def encrypt(msg, MORSE_CODE_DICTIONARY):
8+
li1 = list(MORSE_CODE_DICTIONARY.keys())
9+
wordlist = msg.split(" ")
10+
EncryptedMessage = list()
11+
MorseWord = ""
12+
for i in wordlist:
13+
for j in i:
14+
if j.upper() not in li1:
15+
EncryptedMessage.clear()
16+
EncryptedMessage.append(
17+
'CAN NOT BE TRANSLATED TO MORSE CODE!!')
18+
return EncryptedMessage
19+
MorseWord = MorseWord + MORSE_CODE_DICTIONARY[j.upper()]
20+
MorseWord = MorseWord + " "
21+
EncryptedMessage.append(MorseWord)
22+
MorseWord = ""
23+
return EncryptedMessage
24+
25+
26+
def MakeSound(EncryptedMessage):
27+
for i in EncryptedMessage:
28+
for j in i:
29+
LetterList = j.split(" ")
30+
for k in LetterList:
31+
if k == '.':
32+
winsound.Beep(2500, 400)
33+
# time.sleep(0.001)
34+
elif k == '-':
35+
winsound.Beep(2500, 800)
36+
# time.sleep(0.001)
37+
time.sleep(1.5)
38+
time.sleep(3)
39+
40+
41+
if __name__ == "__main__":
42+
MORSE_CODE_DICT = {'A': '.-', 'B': '-...',
43+
'C': '-.-.', 'D': '-..', 'E': '.',
44+
'F': '..-.', 'G': '--.', 'H': '....',
45+
'I': '..', 'J': '.---', 'K': '-.-',
46+
'L': '.-..', 'M': '--', 'N': '-.',
47+
'O': '---', 'P': '.--.', 'Q': '--.-',
48+
'R': '.-.', 'S': '...', 'T': '-',
49+
'U': '..-', 'V': '...-', 'W': '.--',
50+
'X': '-..-', 'Y': '-.--', 'Z': '--..',
51+
'1': '.----', '2': '..---', '3': '...--',
52+
'4': '....-', '5': '.....', '6': '-....',
53+
'7': '--...', '8': '---..', '9': '----.',
54+
'0': '-----', ', ': '--..--', '.': '.-.-.-',
55+
'?': '..--..', '/': '-..-.', '-': '-....-',
56+
'(': '-.--.', ')': '-.--.-'}
57+
e = encrypt('', MORSE_CODE_DICT)
58+
MakeSound(e)
45.7 KB
Loading
91 KB
Loading

Python/MoorseCodeGenerator/moorse.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import encrypt
2+
import decrypt
3+
4+
# here i have used the standard moorse code chart provided by wikipedia and other website
5+
# I have also added a photo in readme which you can check for better understanding
6+
moorsecode = {'A': '.-', 'B': '-...',
7+
'C': '-.-.', 'D': '-..', 'E': '.',
8+
'F': '..-.', 'G': '--.', 'H': '....',
9+
'I': '..', 'J': '.---', 'K': '-.-',
10+
'L': '.-..', 'M': '--', 'N': '-.',
11+
'O': '---', 'P': '.--.', 'Q': '--.-',
12+
'R': '.-.', 'S': '...', 'T': '-',
13+
'U': '..-', 'V': '...-', 'W': '.--',
14+
'X': '-..-', 'Y': '-.--', 'Z': '--..',
15+
'1': '.----', '2': '..---', '3': '...--',
16+
'4': '....-', '5': '.....', '6': '-....',
17+
'7': '--...', '8': '---..', '9': '----.',
18+
'0': '-----', ', ': '--..--', '.': '.-.-.-',
19+
'?': '..--..', '/': '-..-.', '-': '-....-',
20+
'(': '-.--.', ')': '-.--.-'}
21+
22+
if __name__ == "__main__":
23+
while True:
24+
print('\nHello welcome to Tejas Moorse Code translator')
25+
print('press 1 for English to Moorse Code Converter : ')
26+
print('press 2 for Moorse code to English Converter : ')
27+
print('press 3 to exit')
28+
x = input('')
29+
if x == '1':
30+
z = input('Enter the text you want to convert to morse code:')
31+
e_msg = encrypt.encrypt(z, moorsecode)
32+
e_string = ""
33+
for i in e_msg:
34+
e_string = e_string + i + "/ "
35+
e_string = e_string[:-2]
36+
print('encrypted code:' + e_string)
37+
elif x == '2':
38+
z = input('Enter the Moorse Code to convert to english:')
39+
d_msg = decrypt.decrypt(z, moorsecode)
40+
d_string = ""
41+
for i in d_msg:
42+
d_string = d_string + i + ' '
43+
d_string = d_string[:-1]
44+
print(d_string)
45+
elif x == '3':
46+
exit(True)
47+
else:
48+
print('invalid input')
49+
continue

0 commit comments

Comments
 (0)