Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. from subprocess import call
  2. from pymd5 import md5, padding
  3. import os
  4.  
  5. def checkValid(name):
  6. chars = set('()')
  7. with open(name, 'r') as f:
  8. blob = f.readlines()[2:]
  9. for s in blob:
  10. if any((c in chars) for c in s):
  11. return False
  12. return True
  13. def addPad(name):
  14. bytes = os.stat(name).st_size
  15. with open(name, 'a') as f:
  16. f.write(padding(8*bytes))
  17. def concatPad(name1,name2,name3):
  18. bytes1 = os.stat(name1).st_size
  19. f3 = open(name3, 'w')
  20. f2 = open(name2, 'r')
  21. f1 = open(name1, 'r')
  22. prefix = f1.read()
  23. blob = f2.read()
  24. prefix = prefix+padding(8*bytes1)
  25. f3.write(prefix+blob)
  26.  
  27. f1.close
  28. f2.close
  29. f3.close
  30.  
  31. for i in range(1,7):
  32. if i==1:
  33. while True:
  34. call(["./fastcoll", "-p", "324prefix","-o" , "col1_0", "col1_1"])
  35. if (checkValid("col1_0") and checkValid("col1_1")):
  36. break
  37. continue
  38.  
  39. parent = "col"+str(i-1)+"_0"
  40. init = md5(open(parent, "rb").read()).hexdigest()
  41. while True:
  42. call(["./fastcoll", "-i", init,"-o" , "cola", "colb"])
  43. if (checkValid("cola") and checkValid("colb")):
  44. break
  45.  
  46. skip = pow(2,i-1)
  47. idx = 0
  48. for j in range(0,skip):
  49. parent = "col"+str(i-1)+"_"+str(j)
  50. left = "col"+str(i)+"_"+str(idx)
  51. right = "col"+str(i)+"_"+str(idx+1)
  52. concatPad(parent,"cola", left)
  53. concatPad(parent,"colb", right)
  54. idx = idx+2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement