// This is to find what the longest a string can be and still make a unique hash.
// Technically, we already know there isn't one. This is just an exercise.
foreach (hash_algos() as $thisalgo){
$res = check_maxlen($thisalgo);
};
function check_maxlen($thisalgo){
while (1){
$string .= "a";
$thislen = strlen($string);
$thishash = hash("$thisalgo", $string);
if ($thislen > 1){
if ("$thishash" == "$lasthash"){
print "$thisalgo: Max Usable Length " . $thislen - 1 ."
\n";
$string = "";
return($thislen);
};
// break at an arbitrary length that isn't ^2, so this
// doesn't run forever.
if ($thislen >= 999){
print "$thisalgo: No max length found
\n";
return($thislen);
};
};
$lasthash = $thishash;
};
};