Question

I am trying to generate a unique string/id given another relatively large string(consisting of a directory path name), thought of using crypt function. However, it's not working as expected, most probably due to my inability to understand.

here the code & output:

#!/usr/bin/perl 

print "Enter a string:"; 
chomp(my $string = <STDIN>); 

my $encrypted_string = crypt($string,'di'); 

print "\n  the encrypted string is:$encrypted_string";

output:

$ perl crypt_test
 Enter a string:abcdefghi

 the encrypted string is:dipcn0ADeg0Jc
$
$ perl crypt_test
 Enter a string:abcdefgh

 the encrypted string is:dipcn0ADeg0Jc
$
$
$ perl crypt_test
 Enter a string:abcde

 the encrypted string is:diGyhSp4Yvj4M
$

I couldn't understand why it returned the same encrypted string for the first two strings and differed for the third one. Note that salt is same for all.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top