I'm working on a distributed application to discover passwords using brute force and other techniques.
For the brute force part, I will need a password generator library for Rust or a command line tool. It needs to generate all possibilities using a specific character set, a certain password length, and a range.
It's important to have the option to get just a specific range because I intend to distribute these 'password batches' to different workers running in parallel.
For example, generate a 4-digit alphanumeric password getting from the 1001th to the 2000th password.
There's no library that I know of, probably because it's not too complicated to just do yourself:
playground
Explaining the algorithm
Each character is an order of magnitude. In base ten at a password length of four, you would have the 1000s place, then the 100s place, then the 10s place, and finally the 1s place.
(0..width).rev()iterates through3, 2, 1, 0. We can notice that1000is 10^3,100is 10^2,10is 10^1, and1is 10^0; each number corresponds to the power of ten of the numeral place.So the formula for the order of magnitude of place
iis10.pow(i). If we divide our numbernby10.pow(2), we get a number that represents how many full 100s are in the number (integer division will truncate any 10s or 1s). For the number1234 / 10.pow(2)results in12. But we just want that2, so we take the remainder with respect to 10:12 % 10.So for base ten, our code would be
We then extrapolate that to a larger symbol set by replacing
10withchar_set.len(), resulting in the algorithm above.