Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
1,122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # (mask, min, max)
  2. occ = [("?d", 0, 3),
  3.        ("?l", 3, 5),
  4.        ("?u", 1, 1),
  5.        ("?s", 0, 2)]
  6.  
  7. pwlen = [8, 9]
  8.  
  9. from collections import OrderedDict
  10.  
  11. def getMasks(occurrences, length, depth=0):
  12.     char, min, max = occurrences.pop(0)
  13.     char = [char]
  14.     results = []
  15.     for combination in range(min, max+1):
  16.         if not occurrences:
  17.             results += [char*combination]
  18.         else:
  19.             res = getMasks(occurrences[:], length-combination, depth+1)
  20.             if res is not None:
  21.                 results += list(map(lambda apx: char*combination + apx, res))
  22.     if occurrences and not list(filter(
  23.             lambda x: True if len(x) == length else False, results)):
  24.         return None
  25.     return results
  26.  
  27. masks = []
  28.  
  29. for pwl in pwlen:
  30.     masks += getMasks(occ[:], pwl)
  31. masks = filter(lambda msk: True if len(msk) in pwlen else False, masks)
  32. masks = map(lambda x: "".join(x), masks)
  33. masks = OrderedDict.fromkeys(masks)
  34.  
  35. for m in masks:
  36.     print(m)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement