Crypt function in, Perl, is basically used to store sensitive data and passwords using ASCII characters as encrypted strings (this function encrypts the string). Strings can only be encrypted, they can not be decrypted in the same way as encryption is done.
Syntax: $encyrpted_string = crypt $string, $salt;
Arguments passed to the function:
- $string: it is the string that needs to be encrypted.
- $salt: used for selecting an encrypted version from different variations.
Return Value: Function returns an encrypted string
$salt variable can be the combination of any two characters from the below given set:
['.', '/', 0..9, 'A'..'Z', 'a'..'z']
We can use/include more characters other than this given set of characters, this set is just used for the purpose of recommendation. First two characters in the encrypted string are stored as the salt character which can be used for later comparisons. We can even select the characters for salt by using rand function(random selection). We can observe /see large changes in the resulting / final encrypted string, if small changes are made in the $string or $salt.
Example: Below is the example to illustrate the above mentioned crypt function for Encryption.
Decryption In Perl
For decryption, the encrypted password in Perl needs to be decrypted using the
MIME::Base64 module. For decrypting a string we can call or use
decode_base64() function. A single argument in the form of the string is taken as the input by the function in order to return the decoded or decrypted data/password.
$decoded = decode_base64();
Example: Given below is the example that illustrate the decryption process in Perl.
- Perl | split() Function
- Perl | chomp() Function
- Perl | Backtracking in Regular Expression
- Perl | Searching in a File using regex
- Perl | Operators | Set - 1
- Perl | lt operator
- Perl | chop() Function
- Perl | rename() Function
- Perl | Subroutines or Functions
- Perl | Decision Making (if, if-else, Nested–if, if-elsif ladder, unless, unless-else, unless-elsif)
- Perl | Scalars
- Perl | Loops (for, foreach, while, do...while, until, Nested loops)
- Number Guessing Game using Perl
- Perl | Comparing Scalars
- Perl | Removing leading and trailing white spaces (trim)
- Perl | String functions (length, lc, uc, index, rindex)
- Perl | Arrays
- Perl | Data Types
- Perl | undef and the defined function
- Perl | Automatic String to Number Conversion or Casting
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.