[Math][Python] Forgotten password, part II

Previously: https://yurichev.com/blog/comb/.

Now let's use combinations from itertools Python package.

Let's say, you remember that your password has maybe your name, maybe name of your wife, your year of birth, or her, and maybe couple of symbols like "!", "$", "^". import itertools parts=["den", "xenia", "1979", "1985", "secret", "!", "$", "^"]

for i in range(1, 6): # 1..5
for combination in itertools.combinations(parts, i):
print "".join(combination)


Here we enumerate all combinations of given strings, 1-string combinations, then 2-, up to 5-string combinations. No string can appear twice.

...
denxenia1979
denxenia1985
denxeniasecret
denxenia!
denxenia$denxenia^ den19791985 den1979secret den1979! ... xenia1985secret$^
xenia1985!$^ xeniasecret!$^
19791985secret!$19791985secret!^ ...  (218 passwords) Now let's permute all string in all possible ways: import itertools parts=["den", "xenia", "1979", "1985", "secret", "!", "$", "^"]

for i in range(1, 6): # 1..5
for combination in itertools.combinations(parts, i):
for permutation in itertools.permutations(list(combination)):
print "".join(permutation)

...
^den
xenia1979
1979xenia
xenia1985
1985xenia
xeniasecret
secretxenia
xenia!
!xenia
...
^!$1985secret ^!$secret1985
^$1985secret! ^$1985!secret
^$secret1985! ^$secret!1985
^$!1985secret ^$!secret1985


(8800 passwords)

And finally, let's alter all Latin characters in lower/uppercase ways and add leetspeek, as I did before:

import itertools, string

parts=["den", "xenia", "1979", "1985", "!", "$", "^"] for i in range(1, 6): # 1..5 for combination in itertools.combinations(parts, i): for permutation in itertools.permutations(list(combination)): s="".join(permutation) t=[] for char in s: if char.isalpha(): to_be_appended=[string.lower(char), string.upper(char)] if char.lower()=='e': to_be_appended.append('3') elif char.lower()=='i': to_be_appended.append('1') elif char.lower()=='o': to_be_appended.append('0') t.append(to_be_appended) else: t.append([char]) for q in itertools.product(*t): print "".join(q)  ... dEnxenia dEnxeniA dEnxenIa ... D3nx3N1a D3nx3N1A D3nXenia D3nXeniA D3nXenIa ... ^$1979!1985
^$19851979! ^$1985!1979
^$!19791985 ^$!19851979

( 1,348,657 passwords )

Again, you can't try to crack remote server with so many attempts, but this is really possible for password-protected archive, known hash, etc...

Please drop me email about any bug(s) and suggestion(s): dennis(@)yurichev.com.