Split bitstream
Posted: Thu Sep 25, 2008 6:55 am
Hiya, making a custom base64 function:
Basically it gets three letters, and's them, but what i want to do now is split it into 6 bit parts.
Any idea how I should go about this?
Cheers,
Darkzaelus.
Code: Select all
function newbase64($text) {
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234,.~{}#[]';
$length=strlen($text);
$finished=false;
$index=0;
$buffer=0;
while (!$finished) {
for($i=0;$i<3;$i++) {
$letter=ord($text[$index+$i]);
$buffer+=$letter<<9-3*($i+1);
}
for($i=0;$i<3;$i++) {
//Code i'm having problems thinking of.
}
$index+=3;
$finished=true;
}
return $buffer;
}
$text='abc';
$hash=newbase64($text);
print $hash;
Any idea how I should go about this?
Cheers,
Darkzaelus.