Advertisement
Guest User

anon_win_fail_detect.py

a guest
Nov 30th, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. # coding=utf-8
  2.  
  3. import os
  4. import zlib
  5. import hashlib
  6. def md5(fname):
  7. hash_md5 = hashlib.md5()
  8. with open(fname, "rb") as f:
  9. for chunk in iter(lambda: f.read(4096), b""):
  10. hash_md5.update(chunk)
  11. return hash_md5.hexdigest()
  12.  
  13. md5map = {}
  14. md5winarray = []
  15. md5failarray = []
  16.  
  17. print("Reading novells...")
  18. for file in os.listdir("./"):
  19. if str.lower(file).endswith(".zip") or str.lower(file).endswith(".rar") or str.lower(file).endswith(".exe"):
  20. file_hash = md5("./"+file)
  21. md5winarray.append(file_hash)
  22. md5failarray.append(file_hash)
  23. print(file + ": " + file_hash)
  24. md5map[file_hash] = file
  25.  
  26. print("Calculating ratings of "+ str(len(md5winarray)) +" novells...")
  27. md5winarray = sorted(md5winarray, key=str.lower, reverse=False)
  28. md5winhash = ",".join(md5winarray)
  29. md5wincrc = zlib.crc32(md5winhash)
  30. win_index = md5wincrc%len(md5winarray)
  31. win_md5 = md5winarray[win_index]
  32.  
  33. md5failarray = sorted(md5winarray, key=str.lower, reverse=True)
  34. md5failhash = ",".join(md5failarray)
  35. md5failcrc = zlib.crc32(md5failhash)
  36. fail_index = md5failcrc%len(md5failarray)
  37. fail_md5 = md5failarray[fail_index]
  38.  
  39. print("Done! Contest results:")
  40. print("Anon-win: hash="+win_md5+", file="+md5map[win_md5])
  41. print("Anon-fail: hash="+fail_md5+", file="+md5map[fail_md5])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement