forked from Broham/PassGen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
substitute.py
36 lines (33 loc) · 1.22 KB
/
substitute.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
from itertools import product
from lists import subDict
from lists import dummyCharacters
from lists import numbersOnly
#returns the cartesian product of all replaceable characters
def fullSub(password):
letters = []
#place substitution sets into the letters array
for i,val in enumerate(password):
if val in subDict.keys():
letters.append(subDict[val])
else:
letters.append(val)
return product(*letters)
#returns a list of possible passwords by replacing the first letter with common substitutions and appending numbers and letters to the end
def basicSub(password):
passwords = []
middle = password[1:]
replacements = product(subDict[password[0]], dummyCharacters)
for val in replacements:
passwords.append(val[0] + middle + val[1])
return passwords
#same as basic substitution, but appends 0-9999 to the end
def appendNumbers(password):
passwords = []
middle = password[1:]
#creates a list of numbers from 0-9999 including values like 0, 00, 000, and 0000
numCombos = [''.join(p) for n in range(1,5) for p in product(numbersOnly, repeat=n)]
# print "numbers", numCombos
replacements = product(subDict[password[0]], numCombos)
for val in replacements:
passwords.append(val[0] + middle + val[1])
return passwords