\n",strlen($str),$padding);
}
// If we don't have a four byte chunk, append \0s
$str .= str_repeat("\0", $padding);
foreach (unpack('N*',$str) as $chunk) {
// If there is an all zero chunk, it has a shortcut of 'z'
if ($chunk == "\0") {
$ret .= "z";
continue;
}
// Four spaces has a shortcut of 'y'
if ($chunk == 538976288) {
$ret .= "y";
continue;
}
if ($debug) {
var_dump($chunk); print "
\n";
}
// Convert the integer into 5 "quintet" chunks
for ($a = 0; $a < 5; $a++) {
$b = intval($chunk / (pow(85,4 - $a)));
$ret .= chr($b + 33);
if ($debug) {
printf("%03d = %s
\n",$b,chr($b+33));
}
$chunk -= $b * pow(85,4 - $a);
}
}
// If we added some null bytes, we remove them from the final string
if ($padding) {
$ret = preg_replace("/z$/",'!!!!!',$ret);
$ret = substr($ret,0,strlen($ret) - $padding);
}
return $ret;
}
} // End of base85 class