我想要生成一個唯一的字符串/ ID給出另一個相對較大的字符串(由目錄路徑名組成),想到使用crypt函數。然而,這並不像預期的那樣工作,很可能是因爲我無法理解。perl 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
$
我不明白爲什麼它返回相同的加密字符串前兩個字符串和不同的第三個。請注意鹽對所有人都是一樣的。
如果你想唯一的字符串,嘗試數據:: UUID。從Mat的回答可以看出,crypt()函數是古老而有限的。 – frezik