Nos... van egy ilyen kódom C-ben:
#include <string.h>
#include <windows.h>
#include <stdio.h>
#include <math.h>
typedef unsigned long long int64;
// config
char configfile[] = "settings.ini";
char outputfile[ 1<<7 ];
char charset[ 1 << 9 ];
int maxPWLength = 5;
// local vars
int cursorPosition = 0;
int offsetCursor = 0;
int currentLength = 1;
char currentPassword[ 1<<7 ];
int64 estfilesize = 0;
int64 charswritten = 0;
int lastpercentage = 0;
FILE *fp;
int64 pow64(unsigned int base, unsigned int exp)
{
int64 result = 1;
for (unsigned int v=0; v < exp; v++)
result *= base;
return result;
}
void Processbar()
{
int percentage = (charswritten * 100) / estfilesize;
if (percentage > 100) percentage = 100;
char bar[51] = ""; ZeroMemory(bar, sizeof(bar));
if (percentage > lastpercentage)
{
lastpercentage = percentage;
int bars = percentage / 2;
for (int z=0; z <= bars; z++)
bar[z] = '|';
printf("\r [ %-50.50s ] [ %d%% ]", bar, percentage);
}
}
void WritePassword(char* password)
{
fprintf(fp, "%s\n", currentPassword);
charswritten += strlen(password) + 2;
Processbar();
}
BOOL GeneratePosition(int position)
{
for (unsigned int x=0; x < strlen(charset); x++)
{
currentPassword[position] = charset[x];
if (position > 0) GeneratePosition(position-1);
if (((position > 0) && (currentPassword[position] != charset[0])) || (position == 0)) WritePassword(currentPassword);
}
if (cursorPosition == maxPWLength-1) return FALSE;
return TRUE;
}
int main(int argc, char* argv[])
{
// -> main routine
// parse configuration file
char path[ 1<<9 ]; GetCurrentDirectory( sizeof(path)-1, path);
char absconfigfile[ 1<<10 ]; sprintf(absconfigfile, "%s\\%s", path, configfile);
GetPrivateProfileString("PWListGen", "outputfile", "passwords.txt", outputfile, sizeof(outputfile)-1, absconfigfile);
GetPrivateProfileString("PWListGen", "charset", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", charset, sizeof(charset)-1, absconfigfile);
maxPWLength = GetPrivateProfileInt("PWListGen", "maxPWLength", 4, absconfigfile);
cursorPosition = GetPrivateProfileInt("PWListGen", "minPWLength", 1, absconfigfile)-1;
if (maxPWLength < cursorPosition+1) maxPWLength = cursorPosition+1;
for (int x=0; x<=cursorPosition; x++)
currentPassword[x] = charset[0]; // set startpassword
// calculate estimated filesize
/*double estfilesize = 0;
for (int x=1; x <= maxPWLength; x++)
estfilesize += (pow( strlen(charset), x) * (x+2));*/ // inaccurate
for (int x=1; x <= maxPWLength; x++)
estfilesize += pow64(strlen(charset), x) * (x+2); // combinations * length of combination and \r\n
char estfilesizestr[ 1<<7 ] = "";
if (estfilesize < 1024LL)
sprintf(estfilesizestr, "%.2f Bytes", (double)estfilesize);
else if (estfilesize < pow64(1024,2)) {
sprintf(estfilesizestr, "%.2f kBytes", (double)estfilesize / 1024LL); }
else if (estfilesize < pow64(1024,3))
sprintf(estfilesizestr, "%.2f MBytes", (double)estfilesize / pow64(1024,2));
else if (estfilesize < pow64(1024,4))
sprintf(estfilesizestr, "%.2f GBytes", (double)estfilesize / pow64(1024,3));
else if (estfilesize < pow64(1024,5))
sprintf(estfilesizestr, "%.2f TBytes", (double)estfilesize / pow64(1024,4));
else sprintf(estfilesizestr, "too big");
// open filehandle
if (fp = fopen(outputfile, "w"))
{
printf(" + Config:\n\n");
printf(" - output file = %.48s\n", outputfile);
printf(" - charset = [%.256s]\n", charset);
printf(" - min. password length = %d\n", cursorPosition+1);
printf(" - max. password length = %d\n", maxPWLength);
printf(" \n");
printf(" + Estimated file size: %.48s\n\n", estfilesizestr);
printf(" + Opened %.48s successfully... Attempting to write now...\n\n", outputfile);
// doing that generating process
while (GeneratePosition(cursorPosition))
cursorPosition++;
// close filehandle
fclose(fp);
printf("\n\n + Done. \n\n");
getchar();
}
return 0;
}
Van processbar, előre kiszámolja a 'passwords.txt' állomány várható méretét.
A program a futás során egy külső 'settings.ini' állományból tölti be a szükséges configot.
Példa a 'settings.ini'-re:
[PWListGen]
outputfile=passwords.txt
charset=abcdefghijklmnopqrstuvwxyz0123456789
maxPWLength=8
minPWLength=8
A problémámról meg már bőven írtam...