I'm trying to find the maximum number of combinations for a given character set and string length using the formula charsetLength to the power of stringLength.
Simple, right?
My character set contains sixty-two characters, and when the string length is set to eleven characters or more, the power function returns zero.
Here's the code I'm using:
1 2 3 4 5
unsignedlonglong keyspaceSize; // Number of possible combinations
int charsetLength = 62; // Length of charset
int maxChars = 12; // Length of string
keyspaceSize = pow((longdouble)charsetLength, maxChars);
After running this, the value of keyspaceSize will be zero. (obviously it's not correct.) I can't figure out what's wrong here. When I try
cout << pow(62, 12);
Everything works fine, the result is printed in scientific notation.
Any idea how I can get the proper size here?
EDIT: I've just found that a 64-bit integer is too small to hold this number. Are there any cross platform high-speed methods of storing larger integers?