Skip to content

Commit 0c81636

Browse files
committed
Added bulk test method
1 parent 1409239 commit 0c81636

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

RainbowTable.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
CS 55N Autumn 2014 with Dan Boneh
77
----------------------------------------------------------------------------
88
Contains functionality to create a rainbow table and crack a hash for 6-digit lowercase passwords.
9+
----------------------------------------------------------------------------
10+
With a randomly generated rainbow table of 3 million rows and 1000 chain length,
11+
around 80% of passwords can be cracked, with an average time per password
12+
(including failures) at 3 seconds.
913
"""
1014

1115
# Use Python 3
@@ -142,10 +146,24 @@ def test(password=""):
142146
for _ in range(6):
143147
password += random.choice(string.ascii_lowercase)
144148

145-
print("Cracking password: {0}\nH(password): {1}".format(password, H(password)))
149+
print("\nCracking password: {0}\nH(password): {1}".format(password, H(password)))
146150

147151
cracked = crack(H(password))
148152
if cracked:
149153
print("Success! Password: {0}".format(cracked))
154+
return True
150155
else:
151-
print("Unsuccessful :(")
156+
print("Unsuccessful :(")
157+
return False
158+
159+
# Tests random passwords multiple times and prints success rate and average crack time.
160+
def bulk_test(numHashes):
161+
start = time.time()
162+
numSuccess = 0
163+
164+
for i in range(numHashes):
165+
numSuccess += test()
166+
167+
print("""\n{0} out of {1} random hashes were successful!\n
168+
Average time per password (including failures): {2} secs.""" \
169+
.format(numSuccess, numHashes, (time.time() - start) / numHashes))

0 commit comments

Comments
 (0)