-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHashChecker.py
executable file
·43 lines (32 loc) · 1.17 KB
/
HashChecker.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
def checkHash(fileLoc, option):
# Hash calculator ↓
from hashlib import md5, sha256, sha512
# Specifing how many bytes of the file to open at a time ↓
BLOCKSIZE = 4096
# 4096 Byte = 4 KiloByte
# Variables ↓
md5Hasher = md5()
sha256Hasher = sha256()
sha512Hasher = sha512()
with open(fileLoc, 'rb') as file:
fileData = file.read(BLOCKSIZE)
# Conditions for desired hashing ↓
if(option == 'md5'): # MD5sum ↓
while(len(fileData) > 0):
md5Hasher.update(fileData)
fileData = file.read(BLOCKSIZE)
return md5Hasher.hexdigest()
elif(option == 'sha256'): # SHA256sum ↓
while(len(fileData) > 0):
sha256Hasher.update(fileData)
fileData = file.read(BLOCKSIZE)
return sha256Hasher.hexdigest()
elif(option == 'sha512'): # SHA512sum ↓
while(len(fileData) > 0):
sha512Hasher.update(fileData)
fileData = file.read(BLOCKSIZE)
return sha512Hasher.hexdigest()
else:
return -1
if __name__ == '__main__':
print('Hello World')