Advertisement
SooO

Untitled

Nov 16th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. import hashlib, random, string, time, argparse
  2. import profile
  3.  
  4.  
  5. def get_random_string(length):
  6.     return ''.join(random.choice(string.letters.join(string.digits)) for i in range(length))
  7.  
  8.  
  9. def get_truncated_hash(message, k):
  10.     #return hashlib.sha512(message).digest()[-k:]
  11.     return hashlib.sha512(message).digest()[0:k]
  12.  
  13.  
  14.  
  15. def attack(k):
  16.  
  17.     i = 0
  18.     while True:
  19.         hash = get_truncated_hash(str(i), k)
  20.         #print(hash)
  21.         #print hash.encode("hex")
  22.  
  23.         if(hash == "\00" * k):
  24.             print "String is " + str(i)
  25.             print ("hash for s is " + hash.encode("hex"))
  26.             break
  27.         else:
  28.             i = i + 1
  29.  
  30.  
  31. start=time.time()
  32. attack(3)
  33. print(time.time()-start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement