



(55 votes)/* crypt.c written by detour@metalshell.com * * example of using the crypt lib to encrypt * a plain text password, entered at runtime. * * remember to compile with -lcrypt * gcc -lcrypt -o crypt crypt.c * * http://www.metalshell.com/ * */ #include <stdio.h> #include <unistd.h> #include <stdlib.h> char *crypt(const char *key, const char *salt); extern char *getpass(); int main() { char rndChar[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./"; char salt[3]; char *password; /* Seed the random timer */ srandom(time(0)); /* Random salt. (First two char's of the encrypted string) */ salt[0] = rndChar[random() % 64]; salt[1] = rndChar[random() % 64]; salt[3] = 0; /* getpass() turns off character echoing and disables signals by special characters */ password = getpass("Password: "); printf("%s\n", crypt(password, salt)); }