Reputation: 1329
I am actually making a tool which takes minimum length & maximum length and then characters to use and then in the given criteria it writes every possible combination to a wordlist, but is there a way to get how many combinations can be made using Min Length, Max length & Characters
My Code is:
import itertools
min_len = int(input("Min Len: "))
max_len = int(input("Max Len: "))
characters = str(input("Characters To use: "))
for n in range(min_len, max_len + 1):
for xs in itertools.product(characters, repeat=n):
word = ''.join(xs)
print(f"Writing {word}")
I Am On Python3.8, Linux
Thanks For Helping In Advance!
Upvotes: 1
Views: 256
Reputation: 113
This code will work...
from itertools import chain, combinations
min_len = int(input("Min Len: "))
max_len = int(input("Max Len: "))
characters = str(input("Characters To use: "))
combination = list(chain.from_iterable(combinations(characters, i) for i in range(min_len, max_len+1)))
for comb in combination:
print("".join(comb))
Upvotes: 1
Reputation: 11230
Given w
characters, you can create w**n
strings of length n
. So you're looking for w**min_length + ...... + w**max_length
Upvotes: 1