简单C程序中的加密功能不起作用

时间:2019-03-20 16:29:49

标签: c cs50 des crypt

我是NOOB,试图弄清楚如何将一个单词和一个盐传递给DES crypt函数,并打印出一个加密(加密效果差)的密码。我已经阅读了手册页以及此处的几篇文章(关于我正在研究的cyppt和破解问题集),但是仍然不确定我的代码需要如何使用,下面的代码中包含“未定义对crypt的引用。”

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <crypt.h>

#define _XOPEN_SOURCE

char *crypt(const char *key, const char *salt);

int main(void) {

    char *password = "lol";

    char *salt = "50";

    char *encrypted = crypt(password, salt);

    printf("%s\n", encrypted);
    return 0;
}

// should print 50cI2vYkF0YU2 per CS50 crack exercise example.

在问这个问题之前,我已经咨询了以下内容,但仍然不明白如何使我的简单示例正常工作。 http://pubs.opengroup.org/onlinepubs/009695299/functions/crypt.html https://www.quora.com/How-does-the-crypt-function-work-with-some-examples-of-crypt-function-in-C https://cs50.stackexchange.com/questions/23583/cs-des-based-crypt-function crypt() function in C not working

1 个答案:

答案 0 :(得分:0)

在编译时使用以下命令:gcc yourfilename.c -lcrypt