-
Notifications
You must be signed in to change notification settings - Fork 0
/
dec.py
46 lines (40 loc) · 1.14 KB
/
dec.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
import sys
import csv
import glob
import base64
from Crypto.Cipher import ARC4
def all_files(input_path):
return glob.glob(input_path+"/*/*/*")
def valid_keys(csvdata):
for row in csvdata:
if row['alg'] == '4':
yield row
def main():
input_path = sys.argv[1]
input_all_files = all_files(input_path)
print(input_all_files)
output_path = sys.argv[2]
csvfile = sys.argv[3]
csvdata = []
keyset = set()
with open(csvfile, "r") as f:
reader = csv.DictReader(f)
for row in reader:
if row['key'] not in keyset:
csvdata.append(row)
keyset.add(row['key'])
i = 0
for key in valid_keys(csvdata):
key = base64.b64decode(key['key'])
i += 1
j = 0
for filename in input_all_files:
cipher = ARC4.new(key)
with open(filename) as f:
content = f.read()
result = cipher.decrypt(content)
with open(output_path+"/" + str(i) + "." + str(j), "w") as f:
f.write(result)
j += 1
if __name__ == "__main__":
main()