SHARE
TWEET

PHDays Quals 2014: ecc (not really ECC..)

elvanderb Jan 27th, 2014 282 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import hashlib
  2. import sys
  3.  
  4. def xor(a, b):
  5.     return "".join([chr(ord(a[i]) ^ ord(b[i % len(b)])) for i in xrange(len(a))])
  6.  
  7. def derive(i):
  8.         return hashlib.sha256(str(i)).digest()
  9.  
  10. def decrypt(msg, key):
  11.     iv = msg[:8]
  12.     msg = msg[8:]
  13.     stream = hashlib.sha256(iv + key).digest()
  14.     stream = hashlib.sha256(stream + iv + key).digest()
  15.     cipher = xor(msg, stream)
  16.     return cipher
  17.  
  18. sa = set()
  19. sb = set()
  20. ea = "e86e73ce95d5be01428522838f464257af5f3f97577226b8ce".decode("hex")
  21. eb = "d4c17fa1087b1bedca95579b783c43a8b5a18156036f36bbe8".decode("hex")
  22.  
  23. for i in xrange(100000) :
  24.     key = derive(i)
  25.     sa.add(decrypt(ea, key))
  26.     sb.add(decrypt(eb, key))
  27.     if sa & sb :
  28.         print (sa & sb).pop()
  29.         sys.exit(0)
RAW Paste Data
Top