## keyspace calculation

### keyspace calculation

in the following code, i am trying to calculate the keyspace for a given charset and password length (no minimum length).

_current.size() returns the size of the password, _charset.size() returns the size of the charset.

however, by using a 5 char charset and a 7char password length i did not get a correct result. can anyone give me some pointers?

Code: Select all
`int mischief::brute::calculate_keyspace(){   int keyspace = 0;   for(mischief::brutesize i = 0; i != _current.size(); ++i)   {      keyspace += mischief::math::pow(_charset.size(), i);   }   return keyspace;}int mischief::math::pow(const int number, int exponent){   if(exponent == 0) return 1; // n^0 = 1   int result = number;   while (--exponent)   {      result *= number;   }   return result;}`

the formula for calculating keyspace size is, as per the Cain & Abel help file, as follows:
The key space of all possible combination of passwords to try is calculated using the following formula:

KS = L^(m) + L^(m+1) + L^(m+2) + ........ + L^(M)

where
L = character set length
m = min length of the key
M = max length of the key

For example, when you want to crack an half of a LanManager passwords (LM) using the character set "ABCDEFGHIJKLMNOPQRSTUVWXYZ" of 26 letters, the brute-force cracker have to try KS = 26^1 + 26^2 + 26^3 + ...... + 26^7 = 8353082582 different keys.
The whole secret of existence is to have no fear. Never fear what will become of you, depend on no one. Only the moment you reject all help are you freed.
--Buddha

mischief
Poster

Posts: 355
Joined: Wed Jan 07, 2009 4:16 pm
Blog: View Blog (0)

### Re: keyspace calculation

Give you include the empty password, that example should yield 97656 as keysize.
I wrote that pow, so it can't be wrong
The other stuff, doesn't seem to be wrong either.

You might want to cache the result of _charset.size() for performance, unless your compiler is smart enough to figure that out on his own
BhaaL
Poster

Posts: 270
Joined: Sun Apr 13, 2008 11:16 am
Blog: View Blog (0)

### Re: keyspace calculation

my actual result is 19531, BhaaL. using the exact same code.
The whole secret of existence is to have no fear. Never fear what will become of you, depend on no one. Only the moment you reject all help are you freed.
--Buddha

mischief
Poster

Posts: 355
Joined: Wed Jan 07, 2009 4:16 pm
Blog: View Blog (0)