-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextractor.py
38 lines (30 loc) · 928 Bytes
/
extractor.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
import wave as w
import bitarray as b
import headerManager
import securityManager as sm
def extract(fpath, password_provided):
song = w.open(fpath, mode='rb')
songBytes = bytearray(list(song.readframes(song.getnframes())))
h = ""
f = ""
keepExtracting = True
i = 0
while keepExtracting:
if i < 200:
h = h+str((songBytes[i] & 1))
elif i == 200:
hdrBits = b.bitarray(h)
hdr = hdrBits.tostring()
f = f+str((songBytes[i] & 1))
else:
fname, fsize = headerManager.getFileNameSize(hdr)
f = f+str((songBytes[i] & 1))
if i == 200 + (fsize*8):
keepExtracting = False
i = i+1
msg = b.bitarray(f)
decrypted = sm.decrypt(msg, password_provided)
with open(fname, 'wb') as m:
m.write(decrypted)
print("File Extracted Successfully!!")
song.close()