Skip to content

Instantly share code, notes, and snippets.

@Aaron1011
Created December 29, 2012 15:27
Show Gist options
  • Save Aaron1011/4407554 to your computer and use it in GitHub Desktop.
Save Aaron1011/4407554 to your computer and use it in GitHub Desktop.
Password generator
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