Split bitstream

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Darkzaelus
Forum Commoner
Posts: 94
Joined: Tue Sep 09, 2008 7:02 am

Split bitstream

Post by Darkzaelus »

Hiya, making a custom base64 function:

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;
 
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.
Post Reply