import wave import pyaudio from Tkinter import from tkMessageBox impor

  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
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import wave
import pyaudio
from Tkinter import *
from tkMessageBox import *
from tkFileDialog import *
import sys
'''
wav = wave.open('1.wav', mode="r")
(nchannels, sampwidth, framerate, nframes, comptype, compname) = wav.getparams()
#print (nchannels, sampwidth, framerate, nframes, comptype, compname)
#content = wav.readframes(nframes)
'''
def to_bin_8(x):
return bin(x)[2:].zfill(8)
def scrambler(wav_file_for_scram, wav_file_after_scram, segments_count):
wav_file = open(wav_file_for_scram, "rb")
wav_file_bytes = wav_file.read()
wav_file.close()
head_string = wav_file_bytes[:44]
data_string = wav_file_bytes[44:]
bin_str = ''
for i in data_string:
bin_str += (to_bin_8(ord(i)))
wav = open(wav_file_after_scram, "wb")
wav.write(head_string)
otr = len(bin_str)/segments_count
for i in range(otr):
bin_str = bin_str[i:i+otr]
for i in range(len(bin_str)/8):
wav.write(chr(int(bin_str[i:i+8][::-1], 2)))
'''
for i in range(len(bin_str)/8):
wav.write(chr(int(bin_str[i:i+8][::-1], 2)))'''
wav.close()
showinfo("Scrambling", "Successful!")
#mus = pyaudio.PyAudio().open("312-1.wav")
#mus.start_stream()
root = Tk()
root.title('Scrambling')
root.minsize(500, 200)
root.geometry("+450+100")
message_file_name = StringVar(value="Select a file for scrambling")
output_file_name = StringVar(value="Select a file to save the result")
segments_count = IntVar(value="Enter the count of segments")
top_frame = Frame()
top_frame.pack(pady=10, expand='True')
middle_frame = Frame()
middle_frame.pack(pady=10, expand='True')
main_frame = Frame()
main_frame.pack(pady=10, expand='True')
bottom_frame = Frame()
bottom_frame.pack(pady=10, expand='True')
entry_file_name = Entry(top_frame, font="Arial 13", width=38)
entry_file_name['textvariable'] = message_file_name
entry_file_name.pack(side='left', expand='True', padx=5)
button_entry_file_name = Button(top_frame, text='Open', font="Arial 13")
button_entry_file_name['command'] = lambda: message_file_name.set(askopenfilename())
button_entry_file_name.pack(padx=5, expand='True')
output_message_file_name = Entry(middle_frame, font="Arial 13", width=38)
output_message_file_name['textvariable'] = output_file_name
output_message_file_name.pack(side='left', padx=5, expand='True')
button_output_file_name = Button(middle_frame, text='Open', font="Arial 13")
button_output_file_name['command'] = lambda: output_file_name.set(asksaveasfilename())
button_output_file_name.pack(padx=5, expand='True')
segments_count_entry = Entry(main_frame, font="Arial 13", width=38)
segments_count_entry['textvariable'] = segments_count
segments_count_entry.pack(side='left', padx=5, expand='True')
button_start = Button(main_frame, text='Scram', font="Arial 13")
button_start['command'] = lambda: scrambler(message_file_name.get(), output_file_name.get(), segments_count.get())
button_start.pack(side='left', expand='True')
def play_wav(wav_file):
CHUNK = 1024
wf = wave.open(wav_file, 'rb')
p = pyaudio.PyAudio()
stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
channels=wf.getnchannels(),
rate=wf.getframerate(),
output=True)
data = wf.readframes(CHUNK)
while data != '':
stream.write(data)
data = wf.readframes(CHUNK)
stream.stop_stream()
stream.close()
p.terminate()
root.mainloop()