Skip to content

Instantly share code, notes, and snippets.

@Ra1d7
Last active September 16, 2019 16:36
Show Gist options
  • Save Ra1d7/55233e8b959227bc1d2b0d1109cec5da to your computer and use it in GitHub Desktop.
Save Ra1d7/55233e8b959227bc1d2b0d1109cec5da to your computer and use it in GitHub Desktop.
Calculates the checksum of a file or all files in a folder (you can edit the algorithm used easily by replacing each hashlib.sha256 with whatever algorithm you like)
import hashlib
import os
while True:
s = hashlib.sha256()
path = r'{}'.format(input('Path to file or Folder: \033[7m'))
print('\033[0m')
try:
with open(path, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
s.update(chunk)
print('#'*70)
print(' '*10,end='')
print('File ' + path.replace('\\\\','\\'))
print('#'*70)
print('[+] \033[32m'+s.hexdigest()+'\033[0m')
except:
print('#'*70)
print(' '*10,end='')
print('Folder ' + path.replace('\\\\','\\'))
print('#'*70)
for file in os.listdir(path):
try:
with open(path +'\\'+file, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
e=hashlib.sha256()
e.update(chunk)
print('[+] \033[32m'+e.hexdigest()+'\033[0m',file)
except Exception as e:
print(f'\033[31mError Could Not Process {file}\033[0m ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment