Advertisement
joric

gmaxwell's quiz

Oct 23rd, 2011
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.96 KB | None | 0 0
  1. import hashlib
  2. import itertools
  3. import time
  4. import math
  5.  
  6. text = "A8AXWC36F--KF1C-TF-3YW2TG\0-GBM8DOM"
  7. hash = "349cf6e4c59c999dd2df3fbdac8bd840db4a6dc2104b010390850777249f14a7d96fd62a5f828def0315b9c908420c646381fe1b1e67391b3f5bd0588c28fbe0"
  8. #code = "MTGOX-BTC-MYF8W-DWFCA-62GK8-3F31A"
  9.  
  10. def sha512(s):
  11.     return hashlib.sha512(s + "\n").digest().encode('hex')
  12.  
  13. def ftime(seconds):
  14.     m, s = divmod(seconds, 60)
  15.     h, m = divmod(m, 60)
  16.     d, h = divmod(h, 24)
  17.     y, d = divmod(d, 365)
  18.     if y > 1:
  19.         return "%d years" % y
  20.     elif d > 1:
  21.         return "%d days" % d
  22.     else:
  23.         return "%02d:%02d:%02d" % (h, m, s)
  24.  
  25. def bruteforce(text, hash):  
  26.     count = 0
  27.     seconds = 0
  28.     start = int(time.time())
  29. #    pt = itertools.permutations("A8AWC36FKF1F3YW2GM8D")
  30.     pt = itertools.permutations("MYF8WDWFCA26GK38F31A")
  31.     digest = hash.decode('hex')
  32.     for p in pt:    
  33.         a = "".join(p)
  34.         code = "MTGOX-BTC-" + a[0:5] + "-" + a[5:10] + "-" + a[10:15] + "-" + a[15:20]
  35.         if hashlib.sha512(code + "\n").digest() == digest:
  36.             return code
  37.         count = count + 1
  38.         t = int(time.time()) - start
  39.         if seconds < t:
  40.             seconds = t
  41.             ps = count / seconds
  42.             total = math.factorial(20)
  43.             sec_left = (total - count) / ps
  44.             print code
  45.             print "%d seconds, %d hashes, %d per second, %s left" % (seconds, count, ps, ftime(sec_left))
  46.  
  47. def ibwt(r):
  48.     """Apply inverse Burrows-Wheeler transform."""
  49.     table = [""] * len(r)  # Make empty table
  50.     for i in range(len(r)):
  51.         table = sorted(r[i] + table[i] for i in range(len(r)))  # Add a column of r
  52.     s = [row for row in table if row.endswith("\0")][0]  # Find the correct row (ending in "\0")
  53.     return s.rstrip("\0")  # Get rid of trailing null character
  54.        
  55. if __name__ == '__main__':
  56.     code = bruteforce(text, hash)
  57. #    code = ibwt(text)
  58.     print code
  59.     print sha512(code)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement