我正在尝试在给定另一个相对较大的字符串(由目录路径名组成)的情况下生成一个唯一的字符串/id,考虑使用 crypt 函数。但是,它没有按预期工作,很可能是由于我无法理解。
这里的代码和输出:
#!/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";
输出:
$ 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
$
我不明白为什么它为前两个字符串返回相同的加密字符串,而为第三个字符串返回不同的加密字符串。请注意,盐对所有人都是一样的。