Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2020
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.69 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon Aug  3 21:32:07 2020
  4.  
  5. @author: Anon
  6. """
  7.  
  8.  
  9. import os, hashlib, base64, time
  10.  
  11.  
  12. def PackedBase64MD5(fname):
  13.    
  14.     hash_md5 = hashlib.md5()
  15.     with open(fname, "rb") as f:
  16.         for chunk in iter(lambda: f.read(4096), b""):
  17.             hash_md5.update(chunk)
  18.     Base64Encoded = base64.b64encode(hash_md5.digest())
  19.     UTFencodedStr = str(Base64Encoded , "utf-8")
  20.     return  UTFencodedStr
  21.  
  22. def CreatePB64MD5Index(folder):
  23.    
  24.     t0 = time.time()
  25.     print("---------------------------------------")
  26.     print("Creation Hash index for folder: " + folder)
  27.     for filename in os.listdir(folder):
  28.         if not len(os.listdir(folder)) == 0:
  29.             with open("C:\Tmp\HashIndex.txt", 'a', encoding='utf-8') as outfile:
  30.                  full_path = os.path.join(folder, filename)
  31.                  print(PackedBase64MD5(full_path), file=outfile)
  32.         else:
  33.             print("No files in dir")
  34.     t1 = time.time()
  35.     print("Total time: ", t1 - t0, 'seconds')
  36.     print("---------------------------------------")
  37.    
  38.  
  39. def IsInIndex(Hash):
  40.    
  41.     IndexPath = "C:\Tmp\HashIndex.txt"
  42.     if os.path.isfile(IndexPath):
  43.         with open(IndexPath) as HashInFile:
  44.             strings = HashInFile.read()
  45.             if(Hash in strings):
  46.                 print("Hash found")
  47.                 return True
  48.             else:
  49.                 print("Hash not found")
  50.                 return False
  51.     else:
  52.         print("No index file!")
  53.         return False
  54.    
  55. #Testing functions xD
  56. #print(IsInIndex("6aHReQ+gYLIEsoBTaLAC8g==#@#"))    
  57. #myPath = r"C:/Tmp/ChanArchiveOutput/"
  58. #CreatePB64MD5Index("C:\Tmp\ChanBackup 20200803")
  59.  
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement