Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4a6b64e

Browse files
Merge pull request avinashkranjan#699 from aishwaryachand/morse
added Morse Code Translator
2 parents 0ec9b7d + 0ff7fa4 commit 4a6b64e

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
morse_code_dict = { 'A':'.-', 'B':'-...',
2+
'C':'-.-.', 'D':'-..', 'E':'.',
3+
'F':'..-.', 'G':'--.', 'H':'....',
4+
'I':'..', 'J':'.---', 'K':'-.-',
5+
'L':'.-..', 'M':'--', 'N':'-.',
6+
'O':'---', 'P':'.--.', 'Q':'--.-',
7+
'R':'.-.', 'S':'...', 'T':'-',
8+
'U':'..-', 'V':'...-', 'W':'.--',
9+
'X':'-..-', 'Y':'-.--', 'Z':'--..',
10+
'1':'.----', '2':'..---', '3':'...--',
11+
'4':'....-', '5':'.....', '6':'-....',
12+
'7':'--...', '8':'---..', '9':'----.',
13+
'0':'-----', ', ':'--..--', '.':'.-.-.-',
14+
'?':'..--..', '/':'-..-.', '-':'-....-',
15+
'(':'-.--.', ')':'-.--.-'
16+
}
17+
18+
def encrypt(message):
19+
20+
encrypted_text = ""
21+
for letters in message:
22+
if letters != " ":
23+
encrypted_text = encrypted_text + morse_code_dict.get(letters) + " "
24+
25+
else :
26+
encrypted_text += " "
27+
28+
print(encrypted_text)
29+
30+
def decrypt(message):
31+
message += " "
32+
key_ = list(morse_code_dict.keys())
33+
value_ = list(morse_code_dict.values())
34+
code = ""
35+
decrypted_text = ""
36+
37+
for letters in message:
38+
if letters != " ":
39+
code = code + letters
40+
total_space = 0
41+
42+
else:
43+
total_space += 1
44+
if total_space == 2:
45+
decrypted_text += " "
46+
else:
47+
decrypted_text = decrypted_text + key_[value_.index(code)]
48+
code = ""
49+
50+
print(decrypted_text)
51+
52+
53+
54+
55+
text = input("Enter the text: \n")
56+
if text.startswith('.') or text.startswith("-"):
57+
print('---Decrypting The Code---\n')
58+
decrypt(text)
59+
else:
60+
print('---Ecrypting The Text---\n')
61+
encrypt(text.upper())
62+

‎Morse_Code_Translator/README.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
3+
# Morse Code Translator
4+
5+
Morse code is a method used in telecommunication to encode text characters as standardized sequences of two different signal durations, called _dots_ and _dashes_.
6+
7+
[![morse-code.png](https://i.postimg.cc/xdTNPm2V/morse-code.png)](https://postimg.cc/qNS7Jzq1)
8+
9+
## Input
10+
11+
- Run `Morse_Code_Translator.py`.
12+
- Enter the text that need to be Encrypted or Decrypted.
13+
14+
## Output
15+
[![Decrypt.png](https://i.postimg.cc/dt4mgtWb/Decrypt.png)](https://postimg.cc/zVHgg5Y7)
16+
17+
[![Capture.png](https://i.postimg.cc/J7QbBzWs/Capture.png)](https://postimg.cc/23VqsmyY)
18+
19+
## Author
20+
[Aishwarya Chand](https://github.com/aishwaryachand)
21+
22+
23+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /