Skip to content

Commit d7a5f90

Browse files
authoredAug 6, 2020
Add files via upload
1 parent 028174e commit d7a5f90

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
 

‎Morse Code GUI/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#GUI for encrypting and decrypting MOrse Code using python
2+
3+
## How to Use
4+
5+
Run the .py fie or run the following command
6+
7+
> Windows
8+
9+
```bash
10+
python morse.py
11+
```
12+
13+
> Linux
14+
15+
```shell
16+
$ python3 morse.py
17+
```

‎Morse Code GUI/morse.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from tkinter import *
2+
class gui:
3+
def __init__(self,master):
4+
self.master=master
5+
master.title("Morse Code")
6+
self.string=StringVar(master)
7+
self.result=StringVar(master)
8+
self.label2=Label(master,text='Enter the string: ')
9+
self.label2.pack()
10+
self.text1=Entry(master,textvariable=self.string)
11+
self.text1.pack()
12+
self.label4=Label(master,text='Select one of the options:')
13+
self.label4.pack()
14+
self.button1=Button(master,text='Encrypt',command=self.encode)
15+
self.button1.pack()
16+
self.button2=Button(master,text='Decrypt',command=self.decode)
17+
self.button2.pack()
18+
self.label3=Entry(master,textvariable=self.result)
19+
self.label3.pack()
20+
self.button3=Button(master,text='Quit',command=master.destroy)
21+
self.button3.pack()
22+
23+
def encode(self):
24+
d1={' ':'|','a':'.-','b':'-...','c':'-.-.','d':'-..','e':'.','f':'..-.','g':'--.','h':'....','i':'..','j':'.---','k':'-.-','l':'.-..','m':'--','n':'-.','o':'---','p':'.--.','q':'--.-','r':'.-.','s':'...','t':'-','u':'..-','v':'...-','w':'.--','x':'-..-','y':'-.--','z':'--..','0':'-----','1':'.----','2':'..---','3':'...--','4':'....-','5':'.....','6':'-....','7':'--...','8':'---..','9':'----.'}
25+
a=str(self.string.get())
26+
b=''
27+
for i in a:
28+
if i in d1:
29+
b=b+d1[i]
30+
b=b+' '
31+
self.result.set(str(b))
32+
33+
def decode(self):
34+
d2={'|':' ','.-':'a','-...':'b','-.-.':'c','-..':'d','.':'e','..-.':'f','--.':'g','....':'h','..':'i','.---':'j','-.-':'k','.-..':'l','--':'m','-.':'n','---':'o','.--.':'p','--.-':'q','.-.':'r','...':'s','-':'t','..-':'u','...-':'v','.--':'w','-..-':'x','-.--':'y','--..':'z','-----':'0','.----':'1','..---':'2','...--':'3','....-':'4','.....':'5','-....':'6','--...':'7','---..':'8','----.':'9'}
35+
a=str(self.string.get())
36+
a=a.split(" ")
37+
b=''
38+
for i in a:
39+
if i in d2:
40+
b=b+d2[i]
41+
self.result.set(str(b))
42+
43+
root=Tk()
44+
mygui=gui(root)
45+
root.mainloop()

0 commit comments

Comments
 (0)
Please sign in to comment.