-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainLessThan5.py
More file actions
59 lines (50 loc) · 2.15 KB
/
Copy pathMainLessThan5.py
File metadata and controls
59 lines (50 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from TableGenerator import TableGenerator
from PasswordGenerator import PasswordGenerator
from CheckTable import TableCheck
import hashlib
# Number of digits being cracked, 2 digits = 1 byte = 8 bits
# Only use Digits 1..5, use other file for greater than 5
numDigits = 3
# Length of each chain generated in dictionary
lenChains = 10
# Run once to generate all passwords and chains for specified num bytes, uncomment if numDigits changes
PG = PasswordGenerator()
# PG.GenerateHexAllCombinations(numDigits)
# TG = TableGenerator()
# TG.Generate(numDigits, lenChains)
# Generate random password to crack
testPass = PG.GenerateRandomPassword(numDigits)
testHash = hashlib.sha256(testPass.encode('utf-8')).hexdigest()
testHash = testHash[:numDigits]
print("Randomly generated password is: {0} and it's given hash is: {1}".format(
testPass, testHash))
CT = TableCheck()
checkedHashes = []
collision = []
def checkHashes(testHash, numDigits, lenChains, checkedHashes, collisions):
solvedInput = [False, 0]
while (solvedInput[0] == False):
solvedInput = CT.CheckTable(
testHash, numDigits, checkedHashes, lenChains, collisions)
checkedHashes.append(solvedInput[1])
verifiedRes = hashlib.sha256(
solvedInput[1].encode('utf-8')).hexdigest()
verifiedRes = verifiedRes[:numDigits]
return verifiedRes, checkedHashes, solvedInput
verifiedRes, checkedHashes, solvedInput = checkHashes(
testHash, numDigits, lenChains, checkedHashes, collision)
loop = False
while (loop == False):
if (verifiedRes == testHash and solvedInput[1] == testPass):
print("X: {0} is the inverse of the hash of Y: {1} ".format(
solvedInput[1], testHash))
loop = True
elif (verifiedRes == testHash):
print("X: {0} is the inverse of the hash of Y: {1} but does is not equal to testPass: {2}".format(
solvedInput[1], testHash, testPass))
collision.append(solvedInput[1])
verifiedRes, checkedHashes, solvedInput = checkHashes(
testHash, numDigits, lenChains, checkedHashes, collision)
else:
print("Could not find inverse of the hash Y: {0}".format(testHash))
loop = True