-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathour_md5.py
93 lines (70 loc) · 2.67 KB
/
our_md5.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
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
import hashlib
class OurMd5:
static_string = 'INITIAL_TEST'
def __init__(self):
pass
@staticmethod
def _sha1(fname):
hash_md5 = hashlib.sha1()
with open(fname, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
@staticmethod
def _md5(fname):
hash_md5 = hashlib.md5()
with open(fname, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
@staticmethod
def fixed_string_before(file_location):
hash_md5 = hashlib.md5()
hash_md5.update(str.encode(OurMd5.static_string))
with open(file_location, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
@staticmethod
def fixed_string_middle(file_location):
hash_md5 = hashlib.md5()
with open(file_location, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(str.encode(OurMd5.static_string))
hash_md5.update(chunk)
return hash_md5.hexdigest()
@staticmethod
def fixed_string_after(file_location):
hash_md5 = hashlib.md5()
with open(file_location, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
hash_md5.update(str.encode(OurMd5.static_string))
return hash_md5.hexdigest()
@staticmethod
def sha1_before(file_location):
precomputed_sha1 = OurMd5._sha1(file_location)
hash_md5 = hashlib.md5()
hash_md5.update(str.encode(precomputed_sha1))
with open(file_location, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
@staticmethod
def sha1_middle(file_location):
precomputed_sha1 = OurMd5._sha1(file_location)
hash_md5 = hashlib.md5()
with open(file_location, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(str.encode(precomputed_sha1))
hash_md5.update(chunk)
return hash_md5.hexdigest()
@staticmethod
def sha1_after(file_location):
precomputed_sha1 = OurMd5._sha1(file_location)
hash_md5 = hashlib.md5()
with open(file_location, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
hash_md5.update(str.encode(precomputed_sha1))
return hash_md5.hexdigest()