简体   繁体   English

简单 C 程序中的 Crypt 函数不起作用

[英]Crypt function in simple C program not working

I'm a NOOB, trying to figure out how to pass a word and a salt to the DES crypt function, and print out an encrypted (well, poorly encrypted) password.我是一个菜鸟,试图弄清楚如何将一个单词和一个 salt 传递给 DES crypt 函数,并打印出一个加密的(很好,加密很差)的密码。 I have read the manual pages, and a few posts on here (regarding both cyppt and the crack problem set I'm working through), but am still unsure as to what my syntax needs to be per my code below, which has an 'undefined reference to 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.

I've consulted the following before asking this question, and still don't understand how to get my simple example working.在问这个问题之前,我已经查阅了以下内容,但仍然不明白如何让我的简单示例工作。 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 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() 函数在 C 中不起作用

编译时使用: gcc yourfilename.c -lcrypt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM