i had the same problem - came up with an interesting solution for anyone who stumbles on this page (i assume the OP found a solution by now)
so the idea is not to pick an arbitrary base, you will waste bits
echo bit_up("268ad52b8573137664ea27e557759d1f",4,5);
(function source below)
turns
268ad52b8573137664ea27e557759d1f (32 chars)
into
hbain1bj2dr69qh7slbnb78v (26 chars)
or
fCyJkHxncjtCjG9-lntpQv (22 chars)
so you're basically saying each char in the first sequence is 4 bits (base 16) and you want to convert it to 5 bits per char (base 32) or 6 bits (base 64).
i haven't tried to reverse the function which might not work without some additional padding, and a special reverse binary function
in theory, if you had 256 characters to use, you would cut the string in half (4 bits + 4 bits = 8 bits = 256 chars)
here's the function source
function bit_up($code,$start_bits,$end_bits){
// convert to binary
$from_base = pow (2 ,$start_bits);
$length = strlen($code);
$binary = '';
$i = 0;
while($i < $length){
// echo substr($code,$i,1)."*";
$binary .= str_pad(base_convert(substr($code,$i,1), $from_base, 2),$start_bits,"0",STR_PAD_LEFT);
$i ++;
}
echo "\n".$binary."\n";
// convert to new base
$char_base = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
$i = strlen($binary)-$end_bits;
$output = "";
while($i > 0-$end_bits){
$char = base_convert(substr($binary,$i,$end_bits),2,10);
$output = $char_base[$char] . $output;
$i -= $end_bits;
}
return $output;
}