Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from string import ascii_lowercase, ascii_uppercase, digits
- from itertools import product
- import sys
- def stringToBinary(string):
- return ''.join(format(ord(i), 'b').zfill(8) for i in string)
- def getSliceLength(passphrase):
- binaryLen = len(stringToBinary(passphrase))
- result = int(binaryLen - 1)
- while binaryLen % result > 0:
- result -= 1
- return result
- def slicePassPhrase(passphrase, sliceLength):
- binaryPhrase = stringToBinary(passphrase)
- # print('binary phrase: ',binaryPhrase)
- index = 0
- wordsArray = []
- while index < len(binaryPhrase):
- wordsArray.append(binaryPhrase[index:index + sliceLength])
- index += sliceLength
- # print(wordsArray)
- return wordsArray
- def sliceBinaryPhrase(binaryPhrase, sliceLength):
- # binaryPhrase = stringToBinary(passphrase)
- # print('binary phrase: ',binaryPhrase)
- index = 0
- wordsArray = []
- while index < len(binaryPhrase):
- wordsArray.append(binaryPhrase[index:index + sliceLength])
- index += sliceLength
- # print(wordsArray)
- return wordsArray
- def makeNumArray(wordsArray):
- numArray = []
- for word in wordsArray:
- num = int(word)
- numArray.append(num)
- return numArray
- def hashNumArray(numArray, sliceLength):
- result = 12
- for num in numArray:
- result *= num
- return result % (2**sliceLength)
- def digest(passphrase, debug):
- sliceLength = getSliceLength(passphrase)
- result = hashNumArray(makeNumArray(slicePassPhrase(
- stringToBinary(passphrase), sliceLength)), sliceLength)
- if debug:
- print('hash: ', result)
- return result
- def bruteforce(hashedData):
- charset = ""
- charset += ascii_lowercase
- charset += ascii_uppercase
- charset += digits
- min_length = 8
- counter = 0
- found = False
- for length in range(int(min_length), int(min_length) + 1):
- for attempt in product(charset, repeat=length):
- testData = "".join(attempt)
- testHash = digest(testData, False)
- counter += 1
- if counter % 1000 == 0:
- print('already tried: ', counter, 'times')
- if hashedData == testHash:
- print('found collistion ', testData, 'in ', counter, ' runs')
- break
- if found:
- break
- def main():
- data = sys.argv[1]
- hashed = digest(data, True)
- bruteforce(hashed)
- if __name__ == "__main__":
- main()
Add Comment
Please, Sign In to add comment