Starting a word generator from a specific index

I have a password list generator that generates all combinations of a specific character set for a specific length. Naturally, this list is very long, and it takes quite a while to create.

I want to parallelize a process, but ran into an algorithm / math problem.

For example, I want to generate all [az] combinations (26 letters) for a password with a length of 4 characters. The total number of combinations is 26 ^ 4 = 456.976

Parallelize on ex. two processes, I want the process to process the first half and the other to process the second half. 228.488 combinations each.

And now to the question ... The process that should process the second half is hot so that I get from number 228.488 to the combination of letters with which the generator should begin?

I'm looking for a general solution, so if the number of letters or the length of the password is changed, it will still work. Of course, this was decided long ago, perhaps he even has a name. I just donโ€™t know this name, and I canโ€™t use it.

I implement this in C #

Thank.

+4
source share
1 answer

You study the whole space [a-z]^4. There are 26^4various elements in this space .

Just consider the item [a-z]^4as a 4-digit number in the database 26. Given an integer i, you can find its expression in base 26 and get wordwhat you are looking for.

word[0] = i % 26
word[1] = (i / 26) % 26
word[2] = (i / 26 / 26) % 26
word[3] = (i / 26 / 26 / 26) % 26

M, j : j*(26^4/M).

, : 228488, :

word[0] = 228488 % 26             = 0  => 'a'
word[1] = (228488 / 26) % 26      = 0  => 'a'
word[2] = (228488 / 26 / 26) % 26 = 0  => 'a'
word[3] = (228488 / 26 / 26 / 26) = 13 => 'm'
+2

All Articles