0

I found the following code to be used for brute forcing -

import itertools

def bruteforce(charset, length):
    return (''.join(candidate)
        for candidate in itertools.chain.from_iterable(itertools.product(charset, repeat=i)
        for i in range(length, length + 1)))

for attempt in bruteforce('ab', 10):
    # do something

But I would like to have it more smart - be able to pause and to start from the particular attempt.

I am reading the similar question and answers there - Using itertools.product and want to seed a value - but can not understand how to apply make_product used there to my case.

Community
  • 1
  • 1
LA_
  • 19,823
  • 58
  • 172
  • 308
  • 1
    If I understand you corerctly, you want to stop brute forcing and later continue where you stopped. The `itertools` functions should return iterators. If you assign this iterator to a variable, you can iterate over it, break out of the loop if you need to and start iterating over it again once you need to. – ConfusedProgrammer Sep 23 '14 at 14:57

1 Answers1

0

I found that the easiest way to implement it is to use numbers and then convert them to 36-based numeral system. For ex., 806031402130 is equal to aaaaaaaa and 229927546474 is equal to 2xmkxaay. So, it is easy to keep the state by keeping the numeric value.

LA_
  • 19,823
  • 58
  • 172
  • 308