home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / hacking / unix / makepass.c < prev    next >
Encoding:
C/C++ Source or Header  |  2003-06-11  |  1.8 KB  |  96 lines

  1. /*
  2.  * Received: by kropotkin.gnu.ai.mit.edu (15.11/4.0)
  3.  *  id <AA11421@kropotkin.gnu.ai.mit.edu>; Sun, 7 Jul 91 19:20:37 edt
  4.  * Date: Sun, 7 Jul 91 19:20:37 edt
  5.  * Message-Id: <9107072320.AA11421@kropotkin.gnu.ai.mit.edu>
  6.  * To: EDDIE.MIT.EDU!bloom-beacon!spdcc!merk!works!LC717@EDDIE.MIT.EDU
  7.  * Subject: Cyphertext w/o Un*x
  8.  * Cc: tami@gnu.ai.mit.edu
  9.  *
  10.  * MAKEPASS.C - Written 12-Dec-90 by Noah Friedman (friedman@ai.mit.edu)
  11.  *
  12.  *    Usage: makepass [password]
  13.  *
  14.  *    To compile, type "cc -o makepass makepass.c"
  15.  *
  16.  *    This program is public domain.
  17.  */
  18.  
  19. #include <stdio.h>
  20.  
  21.  
  22.  
  23. /*
  24.  * If your compiler claims the file string.h cannot be found, edit this
  25.  * program and replace <string.h> with <strings.h>
  26.  */
  27. #include <string.h>
  28.  
  29. char *xmalloc();
  30. char *makesalt();
  31. char *crypt();
  32.  
  33. main(argc, argv)
  34. int argc;
  35. char **argv;
  36. {
  37.  char *plain, *salt, *result;
  38.  register int len, i;
  39.  
  40.     if (argc != 2) usage(argv[0]);
  41.  
  42.     len = strlen(argv[1]);
  43.  
  44.  
  45.     plain = xmalloc(len + 1);
  46.     strcpy(plain, argv[1]);
  47.     for (i = 0; i < len; i++) argv[1][i] = '\0';
  48.  
  49.     salt = makesalt();
  50.     result = crypt(plain, salt);
  51.  
  52.     puts(result);
  53. }
  54.  
  55. char *xmalloc(n)
  56. {
  57.  char *s;
  58.  char *malloc();
  59.  
  60.     s = malloc(n * sizeof(char));
  61.     if (s == NULL)
  62.       {
  63.        fprintf(stderr, "malloc: Not enough memory.\n", s);
  64.        exit(1);
  65.       }
  66.  
  67.  
  68.     return s;
  69. }
  70.  
  71. char *makesalt()
  72. {
  73.  static char salt[3];
  74.  char ch1, ch2;
  75.  
  76.     srand(getpid() % 32767);
  77.  
  78.     ch1 = ( rand() % 2 == 0 ) ? 'A' : 'a';
  79.     ch2 = ( rand() % 2 == 0 ) ? 'A' : 'a';
  80.  
  81.     salt[0] = ((unsigned char) rand() % 26) + ch1;
  82.     salt[1] = ((unsigned char) rand() % 26) + ch2;
  83.     salt[2] = '\0';
  84.  
  85.     return salt;
  86. }
  87.  
  88. usage(s)
  89.  
  90.  
  91. char *s;
  92. {
  93.  fprintf(stderr, "Usage: %s [password]\n", s);
  94.  exit(1);
  95. }
  96.