Advertisement
hxrussia

Python Mask Word Generator v3.0 functional-style edition

Oct 22nd, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """Python Mask Word Generator v3.0 functional-style edition
  4. Created by [UCTeam] hX (c) December 2011.
  5.  
  6. Module for generating all variants of variants table or mask.
  7.  
  8. This not work on Python 2, because "map" function must be a generator.
  9. """
  10.  
  11. import string
  12. from functools import reduce
  13. from itertools import product
  14. from re import findall, sub
  15.  
  16. wordgen = lambda mask, repls=(('%c', string.ascii_lowercase), ('%C', string.ascii_uppercase), ('%l', string.ascii_letters), ('%d', string.digits), ('%p', string.punctuation), ('%w', string.whitespace), ('%P', string.printable)): (lambda mask: (lambda base: map(lambda variant: reduce(lambda prev, part: sub(r'\[\]', part, prev, 1), variant, base), product(*[(lambda token: token.split('|') if '|' in token else list(token))(token[1:-1]) for token in findall(r'\[.*?\]', mask)])))(sub(r'\[.*?\]', r'[]', mask)))(reduce(lambda prev, repl: prev.replace(*repl), repls, mask))
  17.  
  18. if __name__ == '__main__':
  19.     for word in wordgen('[%c][%d][%d][%d][%c][%c]ru'):
  20.         print(word)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement