-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathword-maker.py
92 lines (71 loc) · 2.93 KB
/
word-maker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from itertools import combinations, permutations
import os.path
from argparse import ArgumentParser
def is_valid_file(parser, arg):
if not os.path.exists(arg):
parser.error("the file %s does not exist." % arg)
else:
return open(arg, 'r') # return an open file handle
parser = ArgumentParser(description='Wordlist manupluation tools')
parser.add_argument('-i', '--infile', dest='input_file', required=True,
help='input text file', metavar="FILE",
type=lambda x: is_valid_file(parser, x))
parser.add_argument('-o', '--outfile', dest='output_file', required=False,
help='output text file', metavar="FILE",
type=lambda x: is_valid_file(parser, x))
args = parser.parse_args()
def read_word_list(file_object):
# Returns one list of words
f = list(file_object)
return [line.rstrip('\n') for line in f]
# def combine_list(word_list):
# # returns a list of words consisting of
# # the combination of all items in a list.
# forward = list(combinations(word_list, 2))
# reverse = list()
# for element in forward:
# reverse.append([element[1], element[0]])
# return forward + reverse
def permute_words(word_list):
# returns a list of words consisting of
# the permutations of all items in a list.
print("word list")
print(word_list)
return list(permutations(word_list, 2))
def permute_word_lists(list_of_word_lists):
# returns a list of each two-word combination, including variants
# of each word.
# Each word's variants are not combined.
for word in list_of_word_lists:
print(word)
# def list_doubles_to_list(doubles_list):
# combined_list = list()
# for x in doubles_list:
# if len(x) > 1:
# combined_list.append(x[0]+x[1])
# combined_list.append(x[1]+x[0])
# return combined_list
def run_sequential_uppercase(word, max_sequential_characters):
# Creates a list of words where one or more sequential letters
# is converted to uppercase, starting from the beginning of
# the word.
word_list = [word]
for x in range(max_sequential_characters):
for character in range(len(word)):
if len(word) - x - character > 0:
word_list.append(word[:character] +
word[character:character + x + 1:].upper() +
word[character + 1 + x:])
return word_list
def process_words(word_list):
words = list()
for word in word_list:
words.append(run_sequential_uppercase(word, 12))
return words
# permute_word_lists([['hello'], ['Hello'], ['goodbye'], ['Goodbye']])
# print(process_words(read_word_list(args.input_file)))
print(args.input_file)
# print(permute_words(read_word_list(args.input_file)))
# processed_words_list = process_words(read_word_list(args.input_file))
# print(processed_words_list)
# print(args.output_file)