mirror of
https://github.com/TheAlgorithms/Python.git
synced 2026-03-13 09:50:19 +08:00
psf/black code formatting (#1277)
This commit is contained in:
committed by
Christian Clauss
parent
07f04a2e55
commit
9eac17a408
@@ -2,68 +2,93 @@
|
||||
|
||||
|
||||
# Dictionary representing the morse code chart
|
||||
MORSE_CODE_DICT = { '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':'--..',
|
||||
'1':'.----', '2':'..---', '3':'...--',
|
||||
'4':'....-', '5':'.....', '6':'-....',
|
||||
'7':'--...', '8':'---..', '9':'----.',
|
||||
'0':'-----', ', ':'--..--', '.':'.-.-.-',
|
||||
'?':'..--..', '/':'-..-.', '-':'-....-',
|
||||
'(':'-.--.', ')':'-.--.-'}
|
||||
MORSE_CODE_DICT = {
|
||||
"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": "--..",
|
||||
"1": ".----",
|
||||
"2": "..---",
|
||||
"3": "...--",
|
||||
"4": "....-",
|
||||
"5": ".....",
|
||||
"6": "-....",
|
||||
"7": "--...",
|
||||
"8": "---..",
|
||||
"9": "----.",
|
||||
"0": "-----",
|
||||
", ": "--..--",
|
||||
".": ".-.-.-",
|
||||
"?": "..--..",
|
||||
"/": "-..-.",
|
||||
"-": "-....-",
|
||||
"(": "-.--.",
|
||||
")": "-.--.-",
|
||||
}
|
||||
|
||||
|
||||
def encrypt(message):
|
||||
cipher = ''
|
||||
cipher = ""
|
||||
for letter in message:
|
||||
if letter != ' ':
|
||||
if letter != " ":
|
||||
|
||||
|
||||
cipher += MORSE_CODE_DICT[letter] + ' '
|
||||
cipher += MORSE_CODE_DICT[letter] + " "
|
||||
else:
|
||||
|
||||
cipher += ' '
|
||||
cipher += " "
|
||||
|
||||
return cipher
|
||||
|
||||
|
||||
def decrypt(message):
|
||||
|
||||
message += ' '
|
||||
message += " "
|
||||
|
||||
decipher = ''
|
||||
citext = ''
|
||||
decipher = ""
|
||||
citext = ""
|
||||
for letter in message:
|
||||
|
||||
if (letter != ' '):
|
||||
|
||||
if letter != " ":
|
||||
|
||||
i = 0
|
||||
|
||||
|
||||
citext += letter
|
||||
|
||||
else:
|
||||
|
||||
i += 1
|
||||
|
||||
if i == 2:
|
||||
|
||||
if i == 2 :
|
||||
|
||||
|
||||
decipher += ' '
|
||||
decipher += " "
|
||||
else:
|
||||
|
||||
|
||||
decipher += list(MORSE_CODE_DICT.keys())[list(MORSE_CODE_DICT
|
||||
.values()).index(citext)]
|
||||
citext = ''
|
||||
decipher += list(MORSE_CODE_DICT.keys())[
|
||||
list(MORSE_CODE_DICT.values()).index(citext)
|
||||
]
|
||||
citext = ""
|
||||
|
||||
return decipher
|
||||
|
||||
@@ -78,5 +103,5 @@ def main():
|
||||
print(result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user