Created
December 29, 2012 15:27
-
-
Save Aaron1011/4407554 to your computer and use it in GitHub Desktop.
Password generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
import copy | |
def powerset(iterable): | |
s = list(iterable) | |
return itertools.chain.from_iterable(itertools.combinations(s, r) for r in range(len(s) + 1)) | |
def passgen(password, CHOICES = {'a': ['@', '4'], 's': ['$', '&']} ): | |
passwords = set([]) | |
combinations = [] | |
matches = {} | |
index = 0 | |
for char in password: | |
if char in CHOICES: | |
for item in CHOICES[char]: | |
if not matches.get(item): | |
matches[item] = [] | |
matches[item].append(index) | |
combinations.append(item) | |
index += 1 | |
combs = powerset(combinations) | |
for comb in combs: | |
passwd = list(password) | |
matches_copy = copy.deepcopy(matches) | |
for choice in comb: | |
passwd[matches_copy[choice].pop(0)] = choice | |
passwords.add("".join(passwd)) | |
return list(passwords) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment