-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhasher.py
29 lines (22 loc) · 950 Bytes
/
hasher.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
import hashlib
import sys
if len(sys.argv)<4:
print("Usage: hasher.py <sourcefile> <chunklist> <hashfile>")
exit(1)
f=open(sys.argv[1],"rb")
splits=["0\n"]+open(sys.argv[2],"r", encoding=sys.stdout.encoding ).readlines()
o=open(sys.argv[3],"wb")
for i in range(0,len(splits)-1):
f.seek(int(splits[i]))
o.write(splits[i].strip("\n").encode(sys.stdout.encoding))
o.write("-".encode(sys.stdout.encoding))
o.write(splits[i+1].strip("\n").encode(sys.stdout.encoding))
o.write("|".encode(sys.stdout.encoding))
o.write(hashlib.md5(f.read(int(splits[i+1])-int(splits[i]))).hexdigest().encode(sys.stdout.encoding))
o.write("\n".encode(sys.stdout.encoding))
tail=f.read()
o.write(splits[-1].strip("\n").encode(sys.stdout.encoding))
o.write("-".encode(sys.stdout.encoding))
o.write(str(f.tell()).encode(sys.stdout.encoding))
o.write("|".encode(sys.stdout.encoding))
o.write(hashlib.md5(tail).hexdigest().encode(sys.stdout.encoding))