所以我正在尝试制作一个蛮力字符串生成器来匹配和比较CUDA中的字符串。在我开始尝试弄乱一门语言之前,我不知道我想让一个在 C++ 中工作。我目前有这个代码。
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int sLength = 0;
int count = 0;
int charReset = 0;
int stop = 0;
int maxValue = 0;
string inString = "";
static const char charSet[] = //define character set to draw from
"0123456789"
"!@#$%^&*"
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int stringLength = sizeof(charSet) - 1;
char genChars()
{
return charSet[count]; //Get character and send to genChars()
}
int main()
{
cout << "Length of string to match?" << endl;
cin >> sLength;
cout << "What string do you want to match?" << endl;
cin >> inString;
string sMatch(sLength, ' ');
while(true)
{
for (int y = 0; y < sLength; y++)
{
sMatch[y] = genChars(); //get the characters
cout << sMatch[y];
if (count == 74)
{
charReset + 1;
count = 0;
}
if (count == 2147000000)
{
count == 0;
maxValue++;
}
}
count++;
if (sMatch == inString) //check for string match
{
cout << endl;
cout << "It took " << count + (charReset * 74) + (maxValue*2147000000) << " randomly generated characters to match the strings." << endl;
cin >> stop;
}
cout << endl;
}
}
现在这段代码运行和编译,但它并没有完全按照我的意愿去做。它将执行 4 个相同的字符,EX。aaaa 或 1111,然后继续下一个,而不像 aaab 或 1112 那样递增。我试过搞乱这样的事情
for (int x = 0; x < sLength; x++)
{
return charSet[count-sLength+x];
}
在我看来,这应该有效,但无济于事。