将ASCII密码破解程序升级为多个字符 我最近开始学习C++,我决定创建一个基本的密码破解控制台程序。在其中,用户输入一个字符,程序尝试猜测用户输入的字符,从第32个ASCII字符开始,一直到第126个,检查ASCII字符是否与用户的字符匹配。如果匹配,它会告诉用户
现在,我想把我的程序从一个字符升级到一个字符串。我希望用户输入一个字符串,然后让程序猜测它。然而,我不知道该怎么做。我试着在网上搜索答案,但没有结果 提前谢谢将ASCII密码破解程序升级为多个字符 我最近开始学习C++,我决定创建一个基本的密码破解控制台程序。在其中,用户输入一个字符,程序尝试猜测用户输入的字符,从第32个ASCII字符开始,一直到第126个,检查ASCII字符是否与用户的字符匹配。如果匹配,它会告诉用户,c++,string,ascii,cstring,C++,String,Ascii,Cstring,现在,我想把我的程序从一个字符升级到一个字符串。我希望用户输入一个字符串,然后让程序猜测它。然而,我不知道该怎么做。我试着在网上搜索答案,但没有结果 提前谢谢 #include <iostream> int main() { using namespace std; char Password; char C1; cout << "Input a character to crack." << endl; cin &
#include <iostream>
int main()
{
using namespace std;
char Password;
char C1;
cout << "Input a character to crack." << endl;
cin >> Password;
for (C1 = 32; C1 < 127; (int)C1++) {
printf("Trying %d\n", C1);
if (C1 == Password) {
cout << "The password is " << C1 << "." << endl;
break;
}
}
system("PAUSE");
return 0;
}
假设您的密码限制为10个字符。然后,您可以单独检查每个字符,并在找到匹配项时将其添加到另一个charactersstring数组中
#include <iostream>
#include <stdio>
int checkCH(char a , char b)//functions checks equality among characters
{
int k = 0;
if (a==b)
k=1;
return k;
}
int main()
{
char pass[10] , chkr[10] , thepass[10];
int x;
cout<<"Enter Password:";gets(pass);//in case password has a space
for (x = 0 ; x<10 ; x++)
{
cout<<endl;
cout<<"Checking possible match for character number"<<x<<endl;
cout<<endl;
for (int i = 65 ; i<127 ; i++)
{
chkr[x]=char(i);
cout<<" Searching--"<<chkr[x]<<endl;//shows user what the program is searching for
if (checkCH(pass[x],chkr[x]))//check if randomly generate character matches a character in the password
thepass[x]=chkr[x];
}
}
thepass[x--]='\0';//terminate the array
cout<<"Password is - "<<thepass ;
return 0;
}
但是,当您可以直接使用xP时,为什么要这样做:
char mypass[10];
gets(mypass);
cout<<"Password is --"<<mypass<<endl;
看起来您希望循环所有可能的字符串。有长度限制吗?无论如何,你的问题与密码无关。