Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Mon Aug 3 21:32:07 2020
- @author: Anon
- """
- import os, hashlib, base64, time
- def PackedBase64MD5(fname):
- hash_md5 = hashlib.md5()
- with open(fname, "rb") as f:
- for chunk in iter(lambda: f.read(4096), b""):
- hash_md5.update(chunk)
- Base64Encoded = base64.b64encode(hash_md5.digest())
- UTFencodedStr = str(Base64Encoded , "utf-8")
- return UTFencodedStr
- def CreatePB64MD5Index(folder):
- t0 = time.time()
- print("---------------------------------------")
- print("Creation Hash index for folder: " + folder)
- for filename in os.listdir(folder):
- if not len(os.listdir(folder)) == 0:
- with open("C:\Tmp\HashIndex.txt", 'a', encoding='utf-8') as outfile:
- full_path = os.path.join(folder, filename)
- print(PackedBase64MD5(full_path), file=outfile)
- else:
- print("No files in dir")
- t1 = time.time()
- print("Total time: ", t1 - t0, 'seconds')
- print("---------------------------------------")
- def IsInIndex(Hash):
- IndexPath = "C:\Tmp\HashIndex.txt"
- if os.path.isfile(IndexPath):
- with open(IndexPath) as HashInFile:
- strings = HashInFile.read()
- if(Hash in strings):
- print("Hash found")
- return True
- else:
- print("Hash not found")
- return False
- else:
- print("No index file!")
- return False
- #Testing functions xD
- #print(IsInIndex("6aHReQ+gYLIEsoBTaLAC8g==#@#"))
- #myPath = r"C:/Tmp/ChanArchiveOutput/"
- #CreatePB64MD5Index("C:\Tmp\ChanBackup 20200803")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement