Cryptography plays an important role in the computing world. All the passwords will be saved in the encrypted format. All the organizations and the websites will store their user’s password in encrypted format. No one will save the password in plain format. Many problems will arise if the passwords were saved in plain format. For example, if the passwords were saved in plain format in the file or in the oracle database, hackers can easily access the file and access their accounts and can transfer all the money to their accounts.
Because of the above said problems, scientists have started the concept of cryptography. The main concept of cryptography is to change the password into some other text and save the changed password in some files or in table. When the user enters the password the password will be encrypted and the password will be compared with the password stored in the password file (if UNIX machine) or in password table.
Many encryption and decryption algorithms are there in the computing technology. Many people had spent their whole life for cryptography. The first encryption program was written for Unix Operating System to maintain the user’s password.
crypt is the common c function used to crypt the string. It is the library function. This function is the one-way encryption method. There is no decryption program or the function is available. The crypt function will have two arguments. First argument is the password and the second argument is the salt. This function will take only the first eight digits and take the first two digits of the salt and create the encrypted password.
The encrypted password is of eight digits. The first two digit of the encrypted password contains the salt key used. The resulting 6 digits is the encrypted password. Crypt function uses the AES like algorithm.
Syntax for crypt function:
crypt( char *key, char *salt);
Sample program to encrypt the string:
printf("Enter the passwd:");
printf("Enter the Salt Key:");
encpasswd = crypt(passwd, salt);
printf("The crypted passwd is: [%s]\n",encpasswd);
The above program will encrypt the passwd and return the encrypted password to the encpasswd. This program works fine in the unix environment.