Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- # Author: Covey
- import itertools
- import argparse
- import sys
- import re
- # Variables to get data from command line arguments
- filename = 'data.txt' # Default value
- count = 3; # Default value
- substitute = False # Default value
- # Reads data from file into list. Throws exception if something fails
- try:
- global datalist
- datalist = open(filename,'r').readlines()
- datalist = [i.strip() for i in datalist] + [i.lower().strip() for i in datalist]
- except:
- print('\nNo datafile found! Exiting...')
- sys.exit(1)
- # Adds optional arguments to the program
- parser = argparse.ArgumentParser()
- parser.add_argument('-c', '--count', help='Number of words to combine the passwordlist into', type=int)
- parser.add_argument('-s', '--substitute', help='Substitute known letter/integer combinations and add to passwordlist', action='store_true')
- parser.add_argument('-f', '--file', help='Specify path to datafile')
- parser.add_argument('-q','--quick', help='Setting this will write each password directly to the output file without any formating or checks. (Strange things may occur in output file)', action='store_true')
- # This function gets called if the '-q | --quick' argument is set. It will combine all the words contained
- # in the datafile to a maximum of 'count' words, and write each password directly to the output file without
- # any formatting or checks. This may lead to strange output and duplicate listings.
- def generateQuick():
- try:
- file = open(filename, 'w')
- [file.write(''.join(j)) for i in range(1, count + 1) for j in itertools.permutations(datalist, i)]
- file.close()
- print('Passwords generated and written to file!')
- except:
- print('\nFailed to write to file! Exiting...')
- sys.exit(1)
- # This function combines all the words contained in datafile into a passwordlist with all possible
- # combinations, no repeated elements, and a maximum length of 'count' words.
- def generateNormal():
- global pwlist
- pwlist = [''.join(j) for i in range(1, count + 1) for j in itertools.permutations(datalist, i)]
- print('Passwords generated!')
- # If argument set, replacing letters with look-alike integers.
- # NB! Using regular expressions like this may produce duplicate values
- def substitute():
- global pwlist
- # Substitutes 'i' and 'I' with the number 1
- pwlist += [re.sub('(i)|(I)', '1', i) for i in pwlist]
- # Substitutes 'a' and 'A' with the number 4
- pwlist += [re.sub('(a)|(A)', '4', i) for i in pwlist]
- # Substitutes 'o' and 'O' with the number 0
- pwlist += [re.sub('(o)|(O)', '0', i) for i in pwlist]
- # Substitutes 'e' and 'E' with the number 3
- pwlist += [re.sub('(e)|(E)', '3', i) for i in pwlist]
- # Substitutes 't' and 'T' with the number 7
- pwlist += [re.sub('(t)|(T)', '7', i) for i in pwlist]
- # Substitutes 's' and 'S' with the number 5
- pwlist += [re.sub('(s)|(S)', '5', i) for i in pwlist]
- # Substitutes 's' and 'S' with the symbol $
- pwlist += [re.sub('(s)|(S)', '$', i) for i in pwlist]
- # Substitutes 'l' and 'L' with the symbol £
- pwlist += [re.sub('(l)|(L)', '£', i) for i in pwlist]
- # Substitutes 'a' and 'A' with the symbol @
- pwlist += [re.sub('(a)|(A)', '@', i) for i in pwlist]
- # Substitutes 'b' with the number 6
- pwlist += [re.sub('b', '6', i) for i in pwlist]
- def formatPasswords():
- global pwlist
- # Removes duplicates present in the list
- pwlist = list(set(pwlist))
- def writeToFile():
- global pwlist
- try:
- # Generates the file containing the passwords, over-writing old file if present
- file = open('password_list.txt', 'w')
- [file.write(i + "\n") for i in pwlist]
- file.close()
- print('Passwords written to file!')
- except:
- print('Failed to write into file! Exiting...')
- sys.exit(1)
- # Check to see if any arguments are present at runtime
- args = parser.parse_args()
- if args.count:
- # Set the number of words to be combined from the datafile
- count = args.c
- if args.substitute:
- # Turns on substitution of look-alike chars
- substitute = True
- if args.file:
- # Uses custom path to datafile
- filename = args.f
- if args.quick:
- generateQuick()
- sys.exit(0)
- else:
- generateNormal()
- if substitute:
- substitute()
- formatPasswords()
- writeToFile()
- sys.exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement