Advertisement
Xavion

Untitled

Apr 18th, 2015
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. class Unhash:
  2.     def __init__(self, minChar, maxChar, maxStrLength):
  3.         self.minChar = minChar
  4.         self.maxChar = maxChar
  5.         self.maxStrLength = maxStrLength
  6.         self.minHashValues = []
  7.         self.maxHashValues = []
  8.         for i in range(self.maxStrLength + 1):
  9.             self.minHashValues.append(31 ** i // 30 * minChar)
  10.         for i in range(self.maxStrLength + 1):
  11.             self.maxHashValues.append(31 ** i // 30 * maxChar)
  12.         self.outputs = []
  13.  
  14.     def GuessHash(self, target, maxLength):
  15.         maxLength = min(maxLength, self.maxStrLength)
  16.        
  17.         currentHash = target
  18.         step = 1 << 32
  19.  
  20.         self.outputs = []
  21.         for i in range(maxLength + 1):
  22.             maxHash = self.maxHashValues[i]
  23.             if currentHash > maxHash:
  24.                 continue
  25.  
  26.             minHash = self.minHashValues[i]
  27.             while currentHash < minHash:
  28.                 currentHash += step
  29.  
  30.             while currentHash <= maxHash:
  31.                 self.GuessLongHash(currentHash, [''] * i, i - 1)
  32.                 currentHash += step
  33.  
  34.     def GuessLongHash(self, target, chars, charPos):
  35.         if target <= self.maxChar:
  36.             ch = target
  37.             if len(self.outputs) % 100000 == 0:
  38.                 print('Progress!')
  39.             if ch >= self.minChar:
  40.                 chars[charPos] = ch
  41.                 self.outputs.append(''.join(chr(i) for i in chars))
  42.             return
  43.  
  44.         c = target % 31
  45.         while c < self.minChar:
  46.             c += 31
  47.  
  48.         while c <= self.maxChar:
  49.             chars[charPos] = c
  50.             self.GuessLongHash((target - c) // 31, chars, charPos - 1)
  51.             c += 31
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement