-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtestRainbow.py
More file actions
56 lines (50 loc) · 1.72 KB
/
testRainbow.py
File metadata and controls
56 lines (50 loc) · 1.72 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
from rainbowGenerator import *
def test(pwd):
rain = RainbowTable()
rain.readFromFile("D:/Coding/Python/RainbowTable/rain.txt")
return rain.crackHash(rain.hashWord(pwd))
def testLots(n):
rain = RainbowTable()
rain.readFromFile("D:/Coding/Python/RainbowTable/rain2.txt")
count = 0
for i in range(1, n):
pwd = rain.randomPassword()
hash = rain.hashWord(pwd)
if rain.crackHash(hash) == pwd:
count += 1
if i % 100 == 0:
print('Tested', i, '/', n, ':', count, ' ', count / i * 100, '%')
return count, count / n * 100
def testAll(res=None):
rain = RainbowTable()
rain.readFromFile("D:/Coding/Python/RainbowTable/rain.txt")
if res == None:
res = rain.allPasswords()
print('Passwords generated')
count = 0
print('Starting cracking passwords')
for i, pwd in enumerate(res):
hash = rain.hashWord(pwd)
if rain.crackHash(hash) == pwd:
count += 1
if i % 100 == 0:
print('Tested', i, '/', len(res), ':', count, ' ', count / len(res))
return count, count / len(res)
def testCollision(chars, pwdLength, func=md5):
table = MockTable(chars, pwdLength, func)
allPwd = table.allPasswords(table)
hashes = []
count = 0
for pwd in allPwd:
h = table.hashWord(table, pwd)
if h in hashes:
count += 1
hashes.append(h)
return count
class MockTable:
def __init__(self, chars, pwdLength, func):
self.chars = chars
self.pwdLength = pwdLength
self.func = func
self.allPasswords = RainbowTable.allPasswords
self.hashWord = RainbowTable.hashWord