Home
 
 
Search:  
C C++ Perl PHP Python HTML ShellScripts
 
 
  Coding Books
  Tutorials
  Search Code
  Browse Code
  Link to Us
  Site News
  Contact Metalshell
 
 
 
  Submit Code   Statistics
 



Cryptography in C and C++    (ISBN: 189311595X)


 

 List Price: $49.95
 Our Price: $34.97
 Used Price:

 Release Date: May, 2001
 Manufacturer: APress (Paperback)
 Sales Rank: 32,713

 Author: Michael Welschenbach









More Info

 Crypt 2001-11-25 02:27:52
 
Category: source:c:encryption
Description: Using the crypt lib, a plain text password is encrypted and printed on the screen
Platform: unix
Author: detour
Viewed: 8778
Rating: 3.9/5 (52 votes)
If you have any questions about this piece of code or still need help, try posting your question on the forum.

 

Printable Version
crypt.c
/* 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));
}
Rate this code:
(Not Helpful)  (Very Helpful) 

 
 
   Developer.*  
   Blue Parrots  
   Technipal  
   Defy Magazine  
   Code Project  
   Prog. Heaven  


Got Money?