commit e34d53d81884405f388c50c8f1b6662948c8f7bb Author: nitowa Date: Sat May 4 01:15:15 2024 +0200 init diff --git a/data/a.wav b/data/a.wav new file mode 100644 index 0000000..beebf9a Binary files /dev/null and b/data/a.wav differ diff --git a/data/b.wav b/data/b.wav new file mode 100644 index 0000000..94fde4b Binary files /dev/null and b/data/b.wav differ diff --git a/data/c.wav b/data/c.wav new file mode 100644 index 0000000..c0da5ca Binary files /dev/null and b/data/c.wav differ diff --git a/data/d.wav b/data/d.wav new file mode 100644 index 0000000..ad49732 Binary files /dev/null and b/data/d.wav differ diff --git a/data/e.wav b/data/e.wav new file mode 100644 index 0000000..6dcc225 Binary files /dev/null and b/data/e.wav differ diff --git a/data/f.wav b/data/f.wav new file mode 100644 index 0000000..9a23e83 Binary files /dev/null and b/data/f.wav differ diff --git a/data/g.wav b/data/g.wav new file mode 100644 index 0000000..7cc3b16 Binary files /dev/null and b/data/g.wav differ diff --git a/data/h.wav b/data/h.wav new file mode 100644 index 0000000..5178b10 Binary files /dev/null and b/data/h.wav differ diff --git a/data/i.wav b/data/i.wav new file mode 100644 index 0000000..9383373 Binary files /dev/null and b/data/i.wav differ diff --git a/data/j.wav b/data/j.wav new file mode 100644 index 0000000..6abd1ff Binary files /dev/null and b/data/j.wav differ diff --git a/data/k.wav b/data/k.wav new file mode 100644 index 0000000..4be4a32 Binary files /dev/null and b/data/k.wav differ diff --git a/data/l.wav b/data/l.wav new file mode 100644 index 0000000..0da66e6 Binary files /dev/null and b/data/l.wav differ diff --git a/data/m.wav b/data/m.wav new file mode 100644 index 0000000..ad0d65d Binary files /dev/null and b/data/m.wav differ diff --git a/data/n.wav b/data/n.wav new file mode 100644 index 0000000..d6c44d0 Binary files /dev/null and b/data/n.wav differ diff --git a/data/o.wav b/data/o.wav new file mode 100644 index 0000000..24c1670 Binary files /dev/null and b/data/o.wav differ diff --git a/data/p.wav b/data/p.wav new file mode 100644 index 0000000..125615e Binary files /dev/null and b/data/p.wav differ diff --git a/data/q.wav b/data/q.wav new file mode 100644 index 0000000..5d960b1 Binary files /dev/null and b/data/q.wav differ diff --git a/data/r.wav b/data/r.wav new file mode 100644 index 0000000..8c0672c Binary files /dev/null and b/data/r.wav differ diff --git a/data/s.wav b/data/s.wav new file mode 100644 index 0000000..20f4492 Binary files /dev/null and b/data/s.wav differ diff --git a/data/silence.wav b/data/silence.wav new file mode 100644 index 0000000..1dd16fd Binary files /dev/null and b/data/silence.wav differ diff --git a/data/spc.wav b/data/spc.wav new file mode 100644 index 0000000..e83bc34 Binary files /dev/null and b/data/spc.wav differ diff --git a/data/t.wav b/data/t.wav new file mode 100644 index 0000000..c50274a Binary files /dev/null and b/data/t.wav differ diff --git a/data/u.wav b/data/u.wav new file mode 100644 index 0000000..a6b534b Binary files /dev/null and b/data/u.wav differ diff --git a/data/v.wav b/data/v.wav new file mode 100644 index 0000000..81c26a6 Binary files /dev/null and b/data/v.wav differ diff --git a/data/w.wav b/data/w.wav new file mode 100644 index 0000000..186325c Binary files /dev/null and b/data/w.wav differ diff --git a/data/x.wav b/data/x.wav new file mode 100644 index 0000000..e07fa42 Binary files /dev/null and b/data/x.wav differ diff --git a/data/y.wav b/data/y.wav new file mode 100644 index 0000000..c9a38c4 Binary files /dev/null and b/data/y.wav differ diff --git a/data/z.wav b/data/z.wav new file mode 100644 index 0000000..a1620fb Binary files /dev/null and b/data/z.wav differ diff --git a/generator.py b/generator.py new file mode 100644 index 0000000..4597fdf --- /dev/null +++ b/generator.py @@ -0,0 +1,51 @@ +import wave +import sys + +alphabet="abcdefghijklmnopqrstuvwxyz " +outfile = "output.wav" +data= [] + +def usage(): + print("Usage:") + print("python3", sys.argv[0], "") + print(" may only contain a-z and spaces") + return + +if len(sys.argv) < 2 or any(map(lambda char: not char in alphabet,sys.argv[1].lower())): + usage() + exit(1) + +if(len(sys.argv[1]) < 250): + print("WARNING: short texts may be much harder to break. You should use at least 250 characters") + +input = sys.argv[1].lower() + +print("Generating keyboard sounds for \"", input, "\"") + +silence = wave.open("./data/silence.wav", 'rb') +data.append([silence.getparams(), silence.readframes(silence.getnframes())]) +data.append([silence.getparams(), silence.readframes(silence.getnframes())]) +silence.close() + +for char in input: + if(char == " "): + char = "spc" + + sound_file = "./data/"+char+".wav" + wav_data = wave.open(sound_file, 'rb') + data.append([wav_data.getparams(), wav_data.readframes(wav_data.getnframes())]) + wav_data.close() + + silence = wave.open("./data/silence.wav", 'rb') + data.append([silence.getparams(), silence.readframes(silence.getnframes())]) + silence.close() + +silence.close() + +output = wave.open(outfile, 'wb') +output.setparams(data[0][0]) +for i in range(len(data)): + output.writeframes(data[i][1]) +output.close() + +print("Your file is at", outfile) \ No newline at end of file diff --git a/solver.py b/solver.py new file mode 100644 index 0000000..7362ace --- /dev/null +++ b/solver.py @@ -0,0 +1,55 @@ +from scipy.io import wavfile +import sys +samplerate, data = wavfile.read('./output.wav') + +if len(sys.argv) < 2: + print("Usage:", "python3", sys.argv[0], "") + exit(1) + +i = 0 +countsilent = 0 +samplefound = 0 + +avg = [] +start = 0 +end = 0 +avg.append([0]) + +for sample in data: + i+=1 + if(sample[1]<100): + countsilent += 1 + if(countsilent > 10000 and sample[1]>100): + countsilent = 0 + #print(str(i)+": sample found") + start = i + samplefound = 1 + if(countsilent > 8000 and samplefound==1): + samplefound = 0 + #print(str(i)+": sample ended") + end = i + avg[len(avg)-1]=avg[len(avg)-1]/(end-start) + avg.append([0]) + if (samplefound == 1): + avg[len(avg)-1] += sample[1] + +alphabet = "abcdefghijklmnopqr stuvwxyz" +avgs = {} + +i=0 + +res="" + +for arr in avg: + value = round(arr[0], 2) + #print(value) + if str(value) not in avgs: + avgs[str(value)]=alphabet[i] + #print(str(value), "is", alphabet[i]) + i+=1 + res+=avgs[str(value)] + + +print(res) +print("\n") +print("plug the substitution cipher into https://www.guballa.de/substitution-solver and hope it worked!") diff --git a/test.sh b/test.sh new file mode 100644 index 0000000..1e3c24d --- /dev/null +++ b/test.sh @@ -0,0 +1,4 @@ +rm output.wav +python ./generator.py "THE DAY HAD BEGUN ON A BRIGHT NOTE THE SUN FINALLY PEELED THROUGH THE RAIN FOR THE FIRST TIME IN A WEEL AND THE FLAG IS PBCTF OPEN BRACE MECHANICAL LEYBOARDS ARE LOUD CLOSE BRACE AND THE BIRDS WERE SINGING IN ITS WARMTH THERE WAS NO WAY TO ANTICIPATE WHAT WAS ABOUT TO HAPPEN" +python ./solver.py output.wav +read -p "Press enter to continue" \ No newline at end of file