Search code examples
c#brute-forceurl-shortener

Generate a bruteforce string given an offset?


Some years back when I was still a beginner at programming, I found some code online that could generate a bruteforce-code given an offset.

So for instance, if I did GetPassword(1) it would return "a", and if I did GetPassword(2) it would return "b" etc.

Every increment of the offset would provide the next possible combination of strings. A minimum and maximum length of the "password to guess" could also be provided.

Now I have no idea where this code is, or what the algorithm is called. I want to implement one myself, since I need it for URL-enshortening purposes. A user generates a URL that I want to look somewhat long these lines: http://fablelane.com/i/abc where "abc" is the code.


Solution

  • You can think of the output from GetPassword as a number in a different base. For example if GetPassword can output upper and lower case alphanumeric then it is in base 62 -> 26 letters + 26 letters + 10 digits.

    GetPassword must convert from base 10 to base 62 in this case. You can use a look up array to find the output characters.

    You can convert from one base to another by using an algorithm such as this:

    Another stackoverflow post