-
Notifications
You must be signed in to change notification settings - Fork 42
/
substitute.py
31 lines (28 loc) · 1.13 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
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 val in password:
if val in subDict.keys():
letters.append(subDict[val])
else:
letters.append(val)
# return list(product(*letters))
return [''.join(item) for item in product(*letters)]
#returns a list of possible passwords by replacing the first letter with common substitutions and appending numbers and letters to the end. If numbers flag is set then append numbers to end
def basicSub(password, numbers=False):
numCombos = [''.join(p) for n in range(1,5) for p in product(numbersOnly, repeat=n)]
characterList = numCombos if numbers else dummyCharacters
passwords = []
middle = password[1:]
replacements = product(subDict[password[0]], characterList)
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):
return basicSub(password, True)