Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import itertools
- import argparse
- parser = argparse.ArgumentParser()
- parser.add_argument("chars", help="The possible password characters")
- parser.add_argument("-m", "--min", help="The minimum length of the password")
- parser.add_argument("-M", "--max", help="The maximum length of the password")
- parser.add_argument("-o", "--output", help="Filename to save output generated")
- #you will notice something weird (action="store_true") that just means the programs shouldn't expect any value from it
- group_parser = parser.add_mutually_exclusive_group()
- group_parser.add_argument("-R", "--repeat", help="If you want some of the characters to repeat", action="store_true")
- group_parser.add_argument("-r", "--noreapeat", help="If you don't want any of the characters to repeat", action="store_true")
- args = parser.parse_args()
- if args.norepeat:
- if args.min and args.max:
- if args.output:
- f = open(args.output, "w")
- for i in range(args.min, args.max):
- res = itertools.permutations(args.chars, i)
- for j in res:
- f.write(''.join(j) + "\n")
- f.close()
- else:
- for i in range(args.min, args.max):
- res = itertools.permutations(args.chars, i)
- for j in res:
- print ''.join(j)
- else:
- if args.output:
- f = open(args.output, "w")
- for i in range(5, 10):
- res = itertools.permutations(args.chars, i)
- for j in res:
- f.write(''.join(j) + "\n")
- f.close()
- else:
- for i in range(5, 10):
- res = itertools.permutations(args.chars, i)
- for j in res:
- print ''.join(j)
- elif args.repeat:
- if args.min and args.max:
- if args.output:
- f = open(args.output, "w")
- for i in range(args.min, args.max):
- res = itertools.product(args.chars, repeat=i)
- for j in res:
- f.write(''.join(j) + "\n")
- f.close()
- else:
- for i in range(args.min, args.max):
- res = itertools.product(args.chars, repeat=i)
- for j in res:
- print ''.join(j)
- else:
- if args.output:
- f = open(args.output, "w")
- for i in range(5, 10):
- res = itertools.product(args.chars, repeat=i)
- for j in res:
- f.write(''.join(j) + "\n")
- f.close()
- else:
- for i in range(5, 10):
- res = itertools.product(args.chars, repeat=i)
- for j in res:
- print ''.join(j)
- raw_input("Press any key to exit...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement