Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Unhash:
- def __init__(self, minChar, maxChar, maxStrLength):
- self.minChar = minChar
- self.maxChar = maxChar
- self.maxStrLength = maxStrLength
- self.minHashValues = []
- self.maxHashValues = []
- for i in range(self.maxStrLength + 1):
- self.minHashValues.append(31 ** i // 30 * minChar)
- for i in range(self.maxStrLength + 1):
- self.maxHashValues.append(31 ** i // 30 * maxChar)
- self.outputs = []
- def GuessHash(self, target, maxLength):
- maxLength = min(maxLength, self.maxStrLength)
- currentHash = target
- step = 1 << 32
- self.outputs = []
- for i in range(maxLength + 1):
- maxHash = self.maxHashValues[i]
- if currentHash > maxHash:
- continue
- minHash = self.minHashValues[i]
- while currentHash < minHash:
- currentHash += step
- while currentHash <= maxHash:
- self.GuessLongHash(currentHash, [''] * i, i - 1)
- currentHash += step
- def GuessLongHash(self, target, chars, charPos):
- if target <= self.maxChar:
- ch = target
- if len(self.outputs) % 100000 == 0:
- print('Progress!')
- if ch >= self.minChar:
- chars[charPos] = ch
- self.outputs.append(''.join(chr(i) for i in chars))
- return
- c = target % 31
- while c < self.minChar:
- c += 31
- while c <= self.maxChar:
- chars[charPos] = c
- self.GuessLongHash((target - c) // 31, chars, charPos - 1)
- c += 31
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement