Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm for generating huge wordlist

Alright, I know this is going to sound bad, like I'm going to use this for un-ethical things, but you have my word that I am not.

I am writing a paper for my Computer and Information Security course and the topic I chose was hashing methods. One of the points that I go over in my paper is MD5 being only one-way and the only way to crack an MD5 hash is to continuously make strings and use an MD5 function, then compare it with the hash you want to crack.

I would like to build a really simple mock-up program to show alongside my paper (we do a presentation and this would be an awesome thing to have), so I wanted to work out an algorithm that makes a string with every possible character combination up to 8 characters. For example the output will be:

a, b, c, ..., aa, ab, ac, ... ba, bb, bc etc etc etc.

It need to include letters, numbers and symbols if possible.

I got partly through the algorithm for this, but unfortunately my programming skills are not up to the task. If anyone can provide a complete algorithm for this I'd be extremely thankful.

Again, if you think I'm a liar and I'm going to use this for hacking purposes you don't have to leave an answer.

Thank you. :)

like image 749
Andy Avatar asked Dec 29 '22 12:12

Andy


2 Answers

In Python, itertools.product does almost all you require -- though it does it for just one "number of repeats", so you'll have to iterate from 1 to 8 (not hard;-). In essence:

import itertools
import string

# whatever you wish as alphabet (lower/upper, digits, punct, &c)
myalphabet = string.ascii_lowercase + string.ascii_digits

def prods(maxlen, alphabet=myalphabet):
  for i in range(1, maxlen+1):
    for s in itertools.product(alphabet, repeat=i):
      yield ''.join(s)

Of course, for an alphabet of length N and K repetitions (8 in your case) this does produce N + N^2 + ... + N^K possibilities (2,901,713,047,668 possibilities for N=36 and K=8), but, what's a few trillion outputs among friends!-)

like image 113
Alex Martelli Avatar answered Jan 05 '23 04:01

Alex Martelli


To implement this i would probably encode integers to base 36 (or more if you wanted symbols).

1 = 1 2 = 2 ... a = 10 b = 12 ..

and so on.

then you would have a number, like 38 and do some divisions, ie:

38/36 = 1 remaider 2 = 12 in base 36

then just run a for loop to your max number you want to encode, something very large and output your encoded numbers.

just for fun i wrote this for you: http://pastebin.antiyes.com/index.php?id=327

like image 31
John Boker Avatar answered Jan 05 '23 04:01

John Boker