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. 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.'
#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