There was a task to write a program that reads the password entered by the user, remembers it, and then selects it using all ASCII character codes. In general, it is all there, but there is a problem - it only works if the password is 3 characters or less. If it is more, then it just hangs, nothing happens, it does not give any errors and exceptions, in the dispatcher the status "does not respond". And the second problem - the first return from variadic_loop does not work. That is, if (pass == givenPass) comes in, cout is triggered, and return is not, that is, when the correct password is found, it continues to spin until it stops, so, for example, the operating time has to be considered inside the function.
Windows 8, MS Visual Studio 2013
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { string dispPass; if (textBox1->Text != "") { textBox1->BackColor = SystemColors::Window; start_time = clock(); // начальное время int asciitotal = 256; char ascii[256]; for (int i = 0; i < asciitotal; i++) { ascii[i] = i; } string givenPass; givenPass = msclr::interop::marshal_as<std::string>(textBox1->Text); int len = textBox1->Text->Length; cout << givenPass<<endl; int *t = new int[len]; t[len] = { 0 }; dispPass=variadic_loop(0, len, t, asciitotal, ascii, givenPass); label2->Text = gcnew String(dispPass.c_str()); unsigned int search_time = end_time - start_time; // искомое время this->label3->Text = "Время: " + search_time / 1000 + " с"; } else { textBox1->BackColor = Color::Salmon; } } string foundPass=""; string variadic_loop(size_t i, size_t n, int *t, int v, char ascii[], string givenPass) { string pass=""; for (int x = 0; x < n;x++) pass.append("x"); for (t[i] = 32; t[i] < v; t[i]++) { if (n == i + 1) { for (int x = 0; x < n; x++) pass[x] = ascii[t[x]]; if (pass==givenPass) { end_time = clock(); // конечное время foundPass = ""; foundPass = foundPass.append(pass); cout << "yes"<<endl; cout << foundPass << endl; return foundPass; } continue; } variadic_loop(i + 1, n, t, v, ascii, givenPass); } return foundPass; }