我链接了 -lcrypt ,问题是无论我的命令行参数如何,我都得到了相同的加密。如果我改变盐,加密似乎只会改变。我的代码中的什么会导致此缺陷?
#define _XOPEN_SOURCE
#include <unistd.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char *enc[])
{
if (argc != 2)
{
printf("Improper command-line arguments\n");
return 1;
}
char *salt = "ZA";
printf("%s \n", crypt(*enc, salt));
}
最佳答案
在 crypt(*enc, salt)
中,您正在加密您的第一个 参数,它是程序的名称,而不是第一个实际参数。请尝试使用 crypt(enc[1], salt)
。
关于c - 为什么 crypt 函数在这里不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21741336/