SHARE
TWEET

MMA CTF 1st 2015: Simple Hash - Bruteforce Script

hxrussia Sep 9th, 2015 160 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env pypy
  2. # -*- coding: utf-8 -*-
  3.  
  4. import itertools
  5. import string
  6.  
  7.  
  8. TARGET = 0x1E1EAB437EEB0
  9. ALPHABET = string.ascii_letters + string.digits
  10.  
  11. MOD = 0x38D7EA4C68025
  12. COEFF = 0x241
  13.  
  14.  
  15. def decode_full_hash_value(value):
  16.     res = ''
  17.     while value:
  18.         code = value % COEFF
  19.         res += chr(code)
  20.         value /= COEFF
  21.     return ''.join(reversed(res))
  22.  
  23.  
  24. for i in itertools.count():  # 0, 1, 2, ...
  25.     try:
  26.         decoded = decode_full_hash_value(TARGET + MOD * i)
  27.     except ValueError:
  28.         # Can be raised if a code of some character >= 256,
  29.         # then we'll just skip this string
  30.         continue
  31.    
  32.     cur_score = sum(ch in ALPHABET for ch in decoded)
  33.     wanted_score = len(decoded)
  34.     if cur_score + 2 >= wanted_score:
  35.         print '{} / {}'.format(cur_score, wanted_score),
  36.         print ''.join('\\x' + hex(ord(ch))[2:].zfill(2) for ch in decoded)
  37.         if cur_score == wanted_score:
  38.             print 'Found:', decoded
RAW Paste Data
Top