首页 > 解决方案 > C语言破解密码

问题描述

问题: 1. 密码用于加密不超过5位的密码。当只剩下 1,2,3,4 用于..语言时,我可以测试 1,2,3,4 数字。但它不适用于 5 位密码。2. 我也想使用代码一次测试不超过 5 位的密码,但我不知道如何实现?

else
{
    string hash = argv[1];
    string alphabet = "abcdefghijklmnopqrestuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
   // salt is the first two letter of hash
   // same key and same salt will come to the same hash
    char salt[2];
    salt[0] = hash[0];
    salt[1] = hash[1];
    char key[5];

    int i,m,n,p,s;


    for (i=0; i<strlen(alphabet); i++)
     {
        for (m=0; m<strlen(alphabet); m++)
        {
            for (n=0; n<strlen(alphabet);n++)
            {
                for (p=0; p<strlen(alphabet); p++)
                {
                    for( s=0; s<strlen(alphabet);s++)
                    {
                     key[0]=alphabet[i];
                     key[1]=alphabet[m];
                     key[2]=alphabet[n];
                     key[3]=alphabet[p];
                     key[4]=alphabet[s];

                     if (strcmp(crypt(key,salt),hash) == 0)
                     {
                       printf("%s\n",key);
                       return 0;
                     }
                    }
                  }

              }

        }

    }
 }

    printf("\n");
}

标签: ccs50

解决方案


推荐阅读