Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  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.             results += list(map(
  20.                 lambda apx: char*combination + apx,
  21.                 getMasks(occurrences[:], length-combination, depth+1)))
  22.     if occurrences and not 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 = list(filter(lambda msk: True if len(msk) in pwlen else False, masks))
  32. masks = list(map(lambda x: "".join(x), masks))
  33. masks = list(OrderedDict.fromkeys(masks))
  34.  
  35. for m in masks:
  36.     print(m)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement