def generate_alphaseq(start, iterations, string, symbol, filename, silent, forbidden, check_digit): #Handle the case where the string is empty if len(string) == 0: if len(symbol) == 0: symbol = '%' string = symbol iStart = int(start) i = int(iStart) end = i + int(iterations) - 1 strToFile = '' while i <= end: ib = base10toN(i, 36) num = ib if check_digit: num = num + str(alpha_luhn.return_checkdigit(ib)) #Check if the number is in the forbidden word list good = True for regex in forbidden: if regex.match(num): good = False break if good: if not silent: print(string.replace(symbol, num)) #Prints the generated number strToFile += num + '\n' else: #If the generated number is not acceptable, add 1 to the end var to assure the requested amount of numbers is generated end += 1 i += 1 if filename != '': try: listFile = open(filename, 'w') listFile.write(strToFile) listFile.close() except: sys.stderr.write('Error when writing to file \'' + filename + '\'')
'-cd', '--check-digit', help= 'If specified, the generated numbers will have a check digit appended to them.', action='store_true') args = parser.parse_args() if args.silent and args.list_filename == '': print( 'Error: If silent mode is enabled, a filename must be specified.') else: if args.convert: #Just convert the number num = base10toN(int(args.start_number), 36) if args.check_digit: num = num + str(alpha_luhn.return_checkdigit(num)) print(num) else: if args.iterations == -1: print( 'Error: If --convert is not specified, a number of iterations must be inserted.' ) nonoes = [] if args.excluded_words != '': for word in args.excluded_words.split(','): if word.strip() != '': nonoes.append( re.compile('.*' + word.strip().upper().replace( '*', '[A-Z0-9]*').replace('?', '[A-Z0-9]?') + '.*'))
parser.add_argument('-sl', '--silent', help='If specified, the generated numbers will not be printed to the screen. If specified and --output is not specified, the script exits with an error.', action='store_true') parser.add_argument('-x', '--excluded-words', help='Word (or list of words, separated by commas (",") ) to exclude from the output. Wildcards "?" and "*" may be used to specify ranges of words.', default='') parser.add_argument('-xf', '--excluded-word-file', help='Name of a file containing a list of words (one per line) to exclude from the output. Wildcards "?" and "*" may be used to specify ranges of words.', default='') parser.add_argument('-c', '--convert', help='Prints the alphanumeric equivalent of the number inserted as start_number (effectively converts it to base 36. Useful for testing)', action='store_true') parser.add_argument('-cd', '--check-digit', help='If specified, the generated numbers will have a check digit appended to them.', action='store_true') args = parser.parse_args() if args.silent and args.list_filename == '': print('Error: If silent mode is enabled, a filename must be specified.') else: if args.convert: #Just convert the number num = base10toN(int(args.start_number), 36) if args.check_digit: num = num + str(alpha_luhn.return_checkdigit(num)) print(num) else: if args.iterations == -1: print('Error: If --convert is not specified, a number of iterations must be inserted.') nonoes = [] if args.excluded_words != '': for word in args.excluded_words.split(','): if word.strip() != '': nonoes.append(re.compile('.*' + word.strip().upper().replace('*', '[A-Z0-9]*').replace('?', '[A-Z0-9]?') + '.*')) if args.excluded_word_file != '': try: fnono = open(args.excluded_word_file, 'r') for line in fnono: