I'm trying to write a python script that takes n keywords and a number as input. This number will be my maximum range of the string that will be written in the wordlist.
1 ° Problem: You have to make as many combinations as possible between these input strings, without losing any possible combination or string in the middle of the path;
2nd Problem: If you exceed the range defined in the input, the string can not be cut, simply the word that does not fit the default "space" is outside the process string in question, but the words that are outside also need to go through the process of having as many combinations as possible with all other words.
My code has a screen output because I'm debugging but the idea is that the output at the end goes to a text file.
I'm almost there, but the strings still come out with a letter or two that should not.
My code is as follows (python 2.7):
import sys
import itertools
maxi = sys.argv[1]
if int(maxi) > 24:
print ">>For secure, the max of range of string was setup as 24<<"
print "Old value: " + maxi
maxi = 24
maxi = int(maxi)
words = sys.argv[2:]
wn = len(words)
print words
print "Inserted Words: " + str(len(words))
cw = 0
cutd = 0
nwords = []
tmp = ""
for word in itertools.imap(''.join, itertools.permutations(words, r=wn)):
if len(word) <= maxi:
nwords.append(word)
nwords = list(set(nwords))
cw = cw+1
#Permutations, slicing of the big ones
else:
word = word[:maxi]
for inp in words:
if word.find(inp) != -1: # if word has inp do, returning != == True:
tmp = word.replace(inp, "")
word = word.replace(tmp,"")
nwords.append(word)
nwords = list(set(nwords))
cutd = cutd+1
print nwords
print "\nWords Count: " + str(cw)
print "\nCutted Words Count: " + str(cutd)
print "\nFinal Words in list: " + str(len(nwords))