-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmorse_code.py
83 lines (76 loc) · 3.13 KB
/
morse_code.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import pyperclip
import time
morse_code = ("-.-.--",".--.-.",".-...","-.--.","-.--.-", #1
"T",".-.-.","-...-","-----",".----", #2
"..---","...--","....-",".....","-....", #3
"--...","---..","----.",".-","-...", #4
"-.-.","-..",".","..-.","--.", #5
"....","..",".---","-.-",".-..", #6
"--","-.","---",".--.","--.-", #7
".-.","...","-","..-","...-", #8
".--","-..-","-.--","--..","---...", #9
".-..-.",".----.","--..--","E", #10
"-..-.","..--..","\\") #11
alphabet_code = ("!","@","&","(",")", #1
"-","+","=","0","1" #2
"2","3","4","5","6", #3
"7","8","9","A","B", #4
"C","D","E","F","G", #5
"H","I","J","K","L", #6
"M","N","O","P","Q", #7
"R","S","T","U","V", #8
"W","X","Y","Z",":", #9
"\"","\'",".",",",".", #10
"/","?"," ") #11
def main_menu():
print("\n1.Encrypt my message\n2.Decrypt my message\n3.Developer Contact\n4.Exit")
main=input("\nEnter your choice:")
if main == "1":
encrypt()
elif main == "2":
decrypt()
elif main == "3":
developer_contact()
elif main == "4":
exit()
else:
print("\nInvalid Input! Try Again!\n")
time.sleep(2.0)
main_menu()
def encrypt():
message = input("\nEnter your message:").upper()
print("")
encrypt_message = ''
for i in message:
try:
index_morse = alphabet_code.index(i)
encrypt_message = encrypt_message + morse_code[index_morse] + " "
except:
print("\nInvalid characters in input!!\n")
main_menu()
print(encrypt_message)
pyperclip.copy(encrypt_message)
print("\nYour message has been copied to clipboard!!\n")
main_menu()
def decrypt():
message = [str(x) for x in input("\nEnter your message:").split()]
print("")
decrypt_message = ''
for i in message:
try:
index_alphabet = morse_code.index(i)
decrypt_message = decrypt_message + alphabet_code[index_alphabet] + " "
except:
print("\nInvalid characters in input!!\n")
main_menu()
print(decrypt_message)
pyperclip.copy(decrypt_message)
print("\nYour message has been copied to clipboard!!\n")
main_menu()
def developer_contact():
print("\nDeveloper Name: Kumar Aditya\nE-mail: aditya.g.2005001@gmail.com\n")
menu2=input("Press any key for Main Menu:")
main_menu()
print("\n\nWelcome to the MORSE CODE ENCRYPT AND DECRYPT")
time.sleep(3.0)
main_menu()