Exception bei Brute-Force-Algorithmus
-
Hi,
ich habe in PHP einen funktionierenden Brute-Force-Algorithmus entwickelt und diesen nun in C++ umgesetzt:
void go(int length, int pos, AnsiString base, TForm1* form, char characters[66], int done) { int amount_chars = 66; for(int i = 0; i < amount_chars-1; i++) { if(i == 0) { base = base + characters[i]; } else { base[pos] = characters[i]; MessageBox(NULL, base.c_str(), "t", MB_OK); } if(length > 1) { go(length-1, pos + 1, base, form, characters, done); } else { done++; form->done->Caption = done; form->ListBox1->Items->Add(base); form->Refresh(); } form->current_word->Caption = base; } } void __fastcall TForm1::btn_crackClick(TObject *Sender) { char characters[66] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_', ',', '.' }; int length = strlen(this->edit_pass->Text.c_str()); this->possibilities->Caption = pow((sizeof(characters) / sizeof(char)), length); go(length, 0, "", this, characters, 0); }
Ich habe nichts illegales vor.
Mein Problem ist, dass ich, wenn das Programm fertig ist, eine Exception bekomme (anscheinend greife ich auf ein nicht definiertes Arrayelement zu - nur wo?)Habt ihr eine Idee?
-
Habe das Problem gefunden!
base[pos] = characters[i];
mag er (warum auch immer) nicht.
Habe das gesamte Programm jett so gelöst:
bool go(int &length, int &pos, AnsiString base, TForm1* form, char characters[66], int &done) { int amount_chars = 66; for(int i = 0; i < amount_chars-1; i++) { if(i == 0) { base = base + characters[i]; } else { char* c = base.c_str(); c[pos] = characters[i]; base = c; } if(length > 1) { if(go(length-1, pos + 1, base, form, characters, done)) { return true; } } else { done++; form->done->Caption = done; form->ProgressBar1->Position = done; form->current_word->Caption = base; form->Refresh(); } if(base == form->edit_pass->Text) { MessageBox(NULL, base.c_str(), "t", MB_OK); return true; } } return false; } void __fastcall TForm1::btn_crackClick(TObject *Sender) { char characters[66] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_', ',', '.' }; int length = strlen(this->edit_pass->Text.c_str()); this->possibilities->Caption = pow((sizeof(characters) / sizeof(char)), length); this->ProgressBar1->Max = this->possibilities->Caption.ToInt(); go(length, 0, "", this, characters, 0); }
Leider ist es übelst langsam. An was kann das liegen? Mein Programmierstil ist nich der beste, komme aus der PHP-Ecke.
MfG
Simon
-
go(length, 0, "", this, characters, 0); ... base[pos] = characters[i];
Da müsste pos doch == 0 sein und base ein AnsiString, falls ich nicht gerade etwas übersehen habe.
VCL-Hilfe schrieb:
AnsiString::operator []
Returns the character at a specified index in the string.char& __fastcall operator [](const int idx);
Description
This operator returns the byte in the string at index value idx. The [] operator assumes a base index of 1. .
-
ahh, danke! Das müsst es sein. Gleich mal testen
-
Es hat funktioniert
base[pos+1] = characters[i];
Aber hast du ne Idee, warum der Code so extrem langsam ist?
Zum Finden von "lol" braucht er bereits 16 Sekunden
-
Anscheinend dauert die Anzeige der Daten auf der GUI so lange.
Wenn ich die rausnehme, geht es ca. 1000x schneller als so.