CRYPT - encrypt a password.

(Compatible with UNIX System V C)


char *crypt();
coded = crypt(password,lock);


char *password;
is an ASCII string giving the password to be encrypted.
char *lock;
is a two-character ASCII string. The characters of this string may be upper or lower case letters, digits, ".", or "/".
char *coded;
points to the encrypted password.


The "crypt" function encrypts a string in accordance with the NBS Data Encryption Standard (DES). The "lock" argument is used to alter the DES algorithm slightly in one of 4096 ways. The "password" is then used as an encryption key to encrypt a built-in constant string.

The result is the constant string encrypted via "password". The first two characters of the "coded" string are the "lock" characters.

Usually, "crypt" is used to encrypt a password and the coded string is then stored. When the time comes to test an input string to see if it matches the password, "crypt" is called to encrypt the input string, using the lock that appears as the first two characters of the encrypted password. In the encrypted input string matches the encrypted password, the input string matches the original password. Note that there is no need to record the original password; just the encrypted version.

The "coded" string is always stored in the same static memory location. Thus each call to "crypt" overwrites the previous "coded" string.

NOTE: the "crypt" function is NOT the method used by most systems to encrypt passwords.

See Also:

expl c lib encrypt

Copyright © 1996, Thinkage Ltd.