【问题标题】:Upgrading ASCII Password Cracker to Multiple Characters将 ASCII 密码破解器升级为多个字符
【发布时间】:2015-02-15 06:14:00
【问题描述】:

我最近开始学习 C++,并决定创建一个基本的密码破解控制台程序。在其中,用户输入一个字符,程序尝试猜测用户输入的字符,从第 32 个 ASCII 字符开始一直到第 126 个,一路检查 ASCII 字符是否与用户的字符匹配。如果匹配,它会告诉用户。

现在,我想将我的程序从字符升级为字符串。我希望用户输入一个字符串,然后让程序猜测它。但是,我不知道该怎么做。我曾尝试在网上搜索答案,但无济于事。

提前致谢!

#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;
}

【问题讨论】:

  • 看起来你想遍历所有可能的字符串。有长度限制吗?无论如何,您的问题与密码无关。

标签: c++ string ascii cstring


【解决方案1】:

假设您的密码限制为 10 个字符。然后,您可以单独检查每个字符,如果找到匹配项,则将其添加到另一个字符数组(字符串)中。

#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;

【讨论】:

    猜你喜欢
    • 2016-02-01
    • 1970-01-01
    • 2013-01-11
    • 2022-01-15
    • 2015-10-18
    • 2016-02-12
    • 1970-01-01
    • 2021-05-19
    • 1970-01-01
    相关资源
    最近更新 更多