-
Notifications
You must be signed in to change notification settings - Fork 0
/
music_cipher_functions.py
58 lines (30 loc) · 1.33 KB
/
music_cipher_functions.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
#hpw to decrypt the sound
def text_to_notes(text):
notes = {"A":"A3","B":"A#3","C":"B3","D":"C3","E":"C#3","F":"D3","G":"D#3","H":"E3","I":"F3","J":"F#3","K":"G3","L":"G#3","M":"A4","N":"A#4","O":"B4","P":"C4","Q":"C#4","R":"D4","S":"D#4","T":"E4","U":"F4","V":"F#4","W":"G4","X":"G#4","Y":"A5","Z":"G#6"}
notes_list = []
for t in text:
if t.upper() in notes.keys():
notes_list.append(notes[str(t.upper())])
return notes_list
def notes_to_freqs(notes_list):
freqs = {"A3":"220","A#3":"233","B3":"247","C3":"131","C#3":"139","D3":"147","D#3":"156","E3":"165","F3":"175","F#3":"185","G3":"196","G#3":"208","A4":"440","A#4":"466","B4":"494","C4":"262","C#4":"277","D4":"294","D#4":"311","E4":"330","F4":"349","F#4":"370","G4":"392","G#4":"415","A5":"880","G#6":"1661"}
freqs_list = []
for n in notes_list:
if n in freqs.keys():
freqs_list.append(freqs[str(n)])
return freqs_list
def play_notes(freqs_list):
dur = 0
import winsound
for f in freqs_list:
if int(f) == 220 or int(f) < 440 :
dur = 3000
elif int(f) == 440 or int(f) < 880 :
dur = 4000
elif int(f) == 880 or int(f) < 1760 :
dur = 5000
winsound.Beep(int(f),dur)
def encrypt(text):
notes_list = text_to_notes(text)
freqs_list = notes_to_freqs(notes_list)
play_notes(freqs_list)