Advertisement
Guest User

Create a Password Dictionary Generating Script - Python

a guest
Jul 13th, 2015
1,987
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.84 KB | None | 0 0
  1. import itertools
  2. import argparse
  3.  
  4. parser = argparse.ArgumentParser()
  5. parser.add_argument("chars", help="The possible password characters")
  6. parser.add_argument("-m", "--min", help="The minimum length of the password")
  7. parser.add_argument("-M", "--max", help="The maximum length of the password")
  8. parser.add_argument("-o", "--output", help="Filename to save output generated")
  9.  
  10. #you will notice something weird (action="store_true") that just means the programs shouldn't expect any value from it
  11. group_parser = parser.add_mutually_exclusive_group()
  12. group_parser.add_argument("-R", "--repeat", help="If you want some of the characters to repeat", action="store_true")
  13. group_parser.add_argument("-r", "--noreapeat", help="If you don't want any of the characters to repeat", action="store_true")
  14.  
  15. args = parser.parse_args()
  16.  
  17. if args.norepeat:
  18.     if args.min and args.max:
  19.         if args.output:
  20.             f = open(args.output, "w")
  21.             for i in range(args.min, args.max):
  22.                 res = itertools.permutations(args.chars, i)
  23.                 for j in res:
  24.                     f.write(''.join(j) + "\n")
  25.  
  26.             f.close()
  27.  
  28.         else:
  29.              for i in range(args.min, args.max):
  30.                   res = itertools.permutations(args.chars, i)
  31.                   for j in res:
  32.                       print ''.join(j)
  33.  
  34.     else:
  35.         if args.output:
  36.             f = open(args.output, "w")
  37.             for i in range(5, 10):
  38.                 res = itertools.permutations(args.chars, i)
  39.                 for j in res:
  40.                     f.write(''.join(j) + "\n")
  41.  
  42.             f.close()
  43.  
  44.         else:
  45.              for i in range(5, 10):
  46.                   res = itertools.permutations(args.chars, i)
  47.                   for j in res:
  48.                       print ''.join(j)
  49.  
  50. elif args.repeat:
  51.       if args.min and args.max:
  52.         if args.output:
  53.             f = open(args.output, "w")
  54.             for i in range(args.min, args.max):
  55.                 res = itertools.product(args.chars, repeat=i)
  56.                 for j in res:
  57.                     f.write(''.join(j) + "\n")
  58.  
  59.             f.close()
  60.  
  61.         else:
  62.              for i in range(args.min, args.max):
  63.                   res = itertools.product(args.chars, repeat=i)
  64.                   for j in res:
  65.                       print ''.join(j)
  66.  
  67.       else:
  68.         if args.output:
  69.             f = open(args.output, "w")
  70.             for i in range(5, 10):
  71.                 res = itertools.product(args.chars, repeat=i)
  72.                 for j in res:
  73.                     f.write(''.join(j) + "\n")
  74.  
  75.             f.close()
  76.  
  77.         else:
  78.              for i in range(5, 10):
  79.                   res = itertools.product(args.chars, repeat=i)
  80.                   for j in res:
  81.                       print ''.join(j)
  82.  
  83.        
  84. raw_input("Press any key to exit...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement