私は範囲の単語を作成するこのコードを持っています、私の問題は 'abcd'(最小範囲= 4、最大範囲= 4)から範囲の単語を作成したいときです 'cdaa'または'ccca'と...と私は重複 'aa'または 'cc'を削除したいと思います...何か方法はありますか?これは私のプログラムにこのような重複を削除するコードを追加することは可能ですか?結果から重複を削除
mycode:
#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 currentword[ 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 Writeword(char* word)
{
fprintf(fp, "%s\n", currentword);
charswritten += strlen(word) + 2;
Processbar();
}
BOOL GeneratePosition(int position)
{
for (unsigned int x=0; x < strlen(charset); x++)
{
currentword[position] = charset[x];
if (position > 0) GeneratePosition(position-1);
if (((position > 0) && (currentword[position] != charset[0])) || (position == 0)) Writeword(currentword);
}
if (cursorPosition == maxPWLength-1) return FALSE;
return TRUE;
}
int main(int argc, char* argv[])
{
// -> header
printf(" \n");
printf(" ################################################################# \n");
printf(" # # \n");
printf(" # word List Generator by sh4d0w` v1.8 # \n");
printf(" # # \n");
printf(" ################################################################# \n");
printf(" \n");
printf(" \n");
// -> 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", "words.txt", outputfile, sizeof(outputfile)-1, absconfigfile);
GetPrivateProfileString("PWListGen", "charset", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 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++)
currentword[x] = charset[0]; // set startword
// 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. word length = %d\n", cursorPosition+1);
printf(" - max. word 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;
}
はsetting.ini:
[WListGen]
outputfile=word.txt
charset=abcd
maxPWLength=4
minPWLength=4
これはなんですか? brute forcerのパスワードジェネレータ? :P – Marlon
ああ!あまりにも多くのコード! –
このコードはC++に関するものは何ですか? – Duck