C 我不知道为什么我';我得到了错误I';我越来越
这是我的密码:C 我不知道为什么我';我得到了错误I';我越来越,c,cryptography,C,Cryptography,这是我的密码: #define _XOPEN_SOURCE #include <unistd.h> #include <stdio.h> #include <math.h> // this means I also need -lm at the execution of my code int main(int argc, char *argv[]) { if(argc != 2) return 1; const char
#define _XOPEN_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <math.h> // this means I also need -lm at the execution of my code
int main(int argc, char *argv[])
{
if(argc != 2)
return 1;
const char salt[] = {argv[1][13], argv[1][12]}; // the value of salt is the first two chars in string argv[1], and the length of the hash is always 13
// This was const char key[9] and accounted for 8 of the errors
char key[9]; // create array of size 9 since one of the values is the null char
long long int i = 32; // initialize the incrementing variable at the lowest value printable ASCII character; long long because it's going to reach very high numbers
int j = (((i - 32))/95); // digit for key 1
int k = ((i - 32)/pow(95,2)); // digit for key 2
int l = ((i - 32)/pow(95,3)); // digit for key 3
int m = ((i - 32)/pow(95,4)); // digit for key 4
int n = ((i - 32)/pow(95,5)); // digit for key 5
int o = ((i - 32)/pow(95,6)); // digit for key 6
int p = ((i - 32)/pow(95,7)); // digit for key 7
while(i < pow(95,8) + pow(95,7) + pow(95,6) + pow(95,5) + pow(95,4) + pow(95,3) + pow(95,2) + 95) // this is inefficient but goes through every combination & string length
{
key[0] = ((i - 32) % 95) + 32;
key[1] = (j % 95) + 32;
key[3] = (k % 95) + 32;
key[4] = (l % 95) + 32;
key[5] = (m % 95) + 32;
key[6] = (n % 95) + 32;
key[7] = (o % 95) + 32;
key[8] = (p % 95) + 32;
if(char *crypt_r(const char *key, const char *salt, struct crypt_data *data) == argv[1]) // compare the hash of the current key string to the inputted hash
{
printf("%s\n", key);
return 0; //print password and exit
}
else // if the hashes don't match, then increment and try again
{
i++;
}
}
}
其中八个来自键[]=
某物,他们说“只读变量不可赋值”
最后一个问题是“if”语句的末尾带有char,它在char下面放了一个箭头,表示“expected expression”。我在这段代码上花了好几个小时,我真的非常感谢您的帮助
注意:我是一名学生,因此解释比“给你,我修复了你的代码”更有帮助。这也违反了这项任务的规定,我将把这篇文章与我的任务联系起来,因为课程要求我承认我在课程的教学人员和教学材料之外得到的任何额外帮助
编辑:我更改了键[],使其不是常量,从而修复了8个错误。最后一个带有“expected expression”(预期表达式)的选项仍然保留。关于这一行:
if(char *crypt_r(const char *key, const char *salt, struct crypt_data *data) == argv[1]) // compare the hash of the current key string to the inputted hash
看起来您复制了crypt\r
的声明,而没有调用函数。区别在于声明告诉您函数是什么,当您调用它时,您需要填写所有内容
例如,如果您有:
char* key;
char* salt;
struct crypt_data* data;
// initialize all of those
那么你可以这样称呼它:
char* result = crypt_r(key, salt, data);
通常,如果您有以下形式的函数:
some_type function_name(another_type parameter_name);
然后该函数返回一个some\u type
,并期望另一个类型作为第一个参数。你不需要重新申报整件事,你只需要给它想要的两样东西:
another_type x = whatever;
some_type result = function_name(x);
您将key
声明为常量,然后尝试为其赋值。e、 g.您正在获取一个常量并试图将其视为变量。变量的初始化j..p
是0
不需要表达式(i-32)/pow(95…)
您确定我不需要表达式吗?我制作它们是为了在我变大的时候增加它们。我不是说你不需要它们,我是说写intj=0代码>。很可能是初始化错误。clang会准确地告诉您做错了什么。你还需要什么?哇,我完全弄错了。我现在明白你的意思了。非常感谢!很高兴我能帮忙。祝你的程序好运。问题:char键[]和char*键[]之间有区别吗?我知道char*意味着它使用指针,但除此之外。是的,char key[]
是一个字符数组,而char*key[]
是一个字符指针数组(通常指向字符的指针是一个字符串,所以这将是一个字符串数组)。您可能需要阅读以下内容:
another_type x = whatever;
some_type result = function_name(x);