/* * crypt(1) * A simple command-line interface to crypt(3), without the annoying bugs and * limitations of the Other Implementations. * * Author: Greg Wooledge * Version: 0.2 * Last modified: 2013-03-29 * License: Public domain * WWW: http://wooledge.org/~greg/crypt/ */ /* * Sample build command: * cc -o crypt crypt.c */ /* * If you're compiling this on a GNU libc system, you may have to link with * -lcrypt. The cryptographic library is separate from the rest of the GNU * libc because of the (former) US export regulations concerning cryptographic * software. Gee, thanks, guys! */ #define _XOPEN_SOURCE /* GNU libc newer than (?) requires this */ #include #include #include #include void help(int ret); int main(int argc, char *argv[]) { char *salt, s[3]; int ret; if (argc <= 1 || argc > 3) { help(1); } else if (argc == 2) { const char SALT[] = "./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; srand(time(NULL)); s[0] = SALT[rand() % sizeof(SALT)]; s[1] = SALT[rand() % sizeof(SALT)]; s[2] = '\0'; salt = s; } else { salt = argv[2]; } ret = puts(crypt(argv[1], salt)); return (ret != EOF); } void help(int ret) { puts("Usage: crypt password [salt]"); puts(" If salt is omitted, a random two-character (DES) salt is chosen."); puts(" The permitted types of salt are system-specific; see crypt(3)."); exit(ret); }