feat: Initial commit
This commit is contained in:
1
EsRiassuntivi/morse/codice.txt
Normal file
1
EsRiassuntivi/morse/codice.txt
Normal file
@@ -0,0 +1 @@
|
||||
... .. ... .- .-.. ...- .. -.-. .... .. .--. ..- --- -.--.-
|
||||
37
EsRiassuntivi/morse/morse.py
Normal file
37
EsRiassuntivi/morse/morse.py
Normal file
@@ -0,0 +1,37 @@
|
||||
def loadMorse(filename: str, to_ascii: bool):
|
||||
fio = open(filename, "r")
|
||||
|
||||
conv_table = {}
|
||||
|
||||
for line in fio:
|
||||
line = line.split()
|
||||
|
||||
if to_ascii:
|
||||
conv_table[line[1].upper()] = line[0]
|
||||
else:
|
||||
conv_table[line[0]] = line[1].upper()
|
||||
|
||||
conv_table[" "] = " "
|
||||
|
||||
return conv_table
|
||||
|
||||
|
||||
def main():
|
||||
to_ascii = input("Vuoi decodificare un file? ") == "si"
|
||||
in_file = input("Inserisci il nome del file: ")
|
||||
|
||||
conv_table = loadMorse("morse.txt", to_ascii)
|
||||
|
||||
with open(in_file, "r") as fio:
|
||||
in_str = fio.readline()
|
||||
|
||||
if to_ascii:
|
||||
for char in in_str.split():
|
||||
print(conv_table[char], end="")
|
||||
else:
|
||||
in_str = list(in_str.upper())
|
||||
for char in in_str:
|
||||
print(conv_table[char], end=" ")
|
||||
|
||||
|
||||
main()
|
||||
44
EsRiassuntivi/morse/morse.txt
Normal file
44
EsRiassuntivi/morse/morse.txt
Normal file
@@ -0,0 +1,44 @@
|
||||
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 -----
|
||||
1
EsRiassuntivi/morse/testo.txt
Normal file
1
EsRiassuntivi/morse/testo.txt
Normal file
@@ -0,0 +1 @@
|
||||
Si salvi chi puo' forza e coraggio
|
||||
Reference in New Issue
Block a user