-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode.py
More file actions
51 lines (42 loc) · 1.34 KB
/
encode.py
File metadata and controls
51 lines (42 loc) · 1.34 KB
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
import sys
import csv
import warnings
from bs4 import XMLParsedAsHTMLWarning
warnings.filterwarnings("ignore", category=XMLParsedAsHTMLWarning)
import textract
import array
def main():
path = str(sys.argv[1])
lines = textract.process(path).decode('utf-8', errors='ignore').lower()
inArray = lines.split("\n")
outArray = []
with open(str(sys.argv[2])) as csvfile:
csvReader = csv.reader(csvfile, delimiter=" ")
for row in csvReader:
for inputstr in row:
for idx, val in enumerate(inArray):
if inputstr in val:
checkIdx = val.find(inputstr)
lastIdx = checkIdx + len(inputstr)
if len(val) <= lastIdx:
lastchar = " "
else:
lastchar = val[lastIdx]
sepList = [ "_", ")", ":", ";", ".", ",", " ", "\"", "'"]
if any (lastchar in s for s in sepList):
outArray.append(idx)
outArray.append(val.find(inputstr))
break
elif idx+1 == len(inArray):
print("the cipher key (document) does not contain value: " + inputstr)
quit()
if len(sys.argv) == 4 and str(sys.argv[3]) == '-b':
with open('out.pcm', 'wb') as out:
pcm_vals = array.array('h', outArray) # 16-bit signed
pcm_vals.tofile(out)
else:
with open("out.csv", "w") as csvfile:
writer = csv.writer(csvfile, lineterminator="\n")
writer.writerow(outArray)
if __name__ == "__main__":
main()