crypt Function in Perl

What is crypt() in Perl?

Explanation

This is used for 56 bit DES encryption,its a one way hash function. In the function plain text and salt is converted into a digest. Small changes made to the plain text or salt will have a large change in digest.

Syntax:


crypt (plaintext, salt)

In the above syntax, this function takes two arguments first argument is "plaintext", second one is the "salt" value.

Example :


#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
$string = "ABV.PNT4TtMZQ";
$string2 = "Hioxindia";
$temp = crypt($string,'AB');
if ($string=$string2)
{
print "Crypt Matches";
}
else
{
print "Crypt Dont Match";
}
Result :

Crypt Matches

In the above example already a string "Hioxindia", with the salt AB is encrypted and the digest is stored in "$string", then the same string "Hioxindia" and salt is explicitly encrypted.It displays an "Crypt Matches".

Ask Questions

Ask Question