-
Notifications
You must be signed in to change notification settings - Fork 2
/
Brute.py
70 lines (56 loc) · 1.92 KB
/
Brute.py
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
60
61
62
63
64
65
66
67
68
69
70
import time
class Brute:
def __init__(self):
self.testChars = "abcdefghijklmnopqrstuvwxyz"
self.printCount = 0
self.pwLen = 0
self.userPw = ''
self.pwList = list()
self.maxPwLen = 0
self.start = 0
self.stop = 0
def setPassword(self, inputPw):
self.userPw = inputPw
self.pwList = list(inputPw)
self.maxPwLen = len(self.pwList)
def checkPwForLen(self, pwLen):
generatedPw = [self.testChars[0]] * pwLen
while generatedPw != [self.testChars[-1]] * pwLen:
self.incrementPw(generatedPw)
self.printCount += 1
if self.printCount % 10000 == 0:
print('TESTING:', generatedPw)
if generatedPw == self.pwList:
print('TESTING:', generatedPw)
print('FOUND:', ''.join(generatedPw))
return True
return False
def incrementPw(self, generatedPw):
incr = 0
while True:
# TODO: find is too slow (profiler tested)
pos = self.testChars.find(generatedPw[incr])
if pos == len(self.testChars)-1:
generatedPw[incr] = self.testChars[0]
incr += 1
if incr > len(generatedPw)-1:
break
else:
generatedPw[incr] = self.testChars[pos + 1]
break
def processPassword(self):
self.start = time.time()
for i in range(self.maxPwLen):
if self.checkPwForLen(i + 1):
break
self.stop = time.time()
def getDuration(self):
return self.stop - self.start
if __name__ == '__main__':
force = Brute()
# testChars = "0987654321"
# testChars = "abcdefghijklmnopqrstuvwxyz0987654321"
force.setPassword('test')
force.processPassword()
print('DURATION:', force.getDuration())
print('CHECKED:', force.printCount)