DeaD_EyE

calculate_zerobytes_md5

Sep 23rd, 2020
462
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import hashlib
  2.  
  3.  
  4. def calculate_zerobytes_md5(size):
  5.     def multiple(value):
  6.         results = []
  7.         for unit in (0, 1, 2):
  8.             for multi in (16, 32, 64, 128, 256, 512):
  9.                 result = value / multi / (1024 ** unit)
  10.                 if result.is_integer():
  11.                     results.append(multi * 1024 ** unit)
  12.         return results[-1]
  13.     chunk_size = multiple(size)
  14.     zerobytes = b"\x00" * chunk_size
  15.     iterations = size // chunk_size
  16.     md5 = hashlib.md5()
  17.     for _ in range(iterations):
  18.         md5.update(zerobytes)
  19.     return md5.hexdigest()
  20.  
  21.  
  22.  
  23. # >>> calculate_zerobytes_md5(7743733760)
  24. # '30e109af780fd3763a013b4adf3ceb71'
  25. # >>> calculate_zerobytes_md5(0)
  26. # 'd41d8cd98f00b204e9800998ecf8427e'
RAW Paste Data