New class proposal

From: Date: Sat, 07 Dec 2002 17:36:09 +0000
Subject: New class proposal
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-11431@lists.php.net to get a copy of this message
Hi, I was wondering if their's a need for an base conversion class in pear. The class accepts an character string which it will use to encode decimal numbers and decode the code (result of encoding function). In some way it works like the base_convert function, only here any combination of printable characters can be used. Personaly i came til 96 characters. A quick example will clear the sky: $base = new basex("ABCDEF") $code = base->encode(123456); $code will now contains 'CDFBDCA'. Ofcouse you can also decode the code back. function convert_base($code, $oldbase, $newbase) { // take old base an input $base = new basex($oldbase); //convert code to base10 decimal number $number = $base->decode($code); //change to the new base $base->init($newbase); //encode the decimal number and return the result to the function return $base->encode($number); } above function does exaclty the same as base_convert, only with your own character base set. $newcode = convert_base("5c", "012345679abcdef", "fedcba9876543210"); This would result in "a9" I called my class baseX and i want to put it in math_basex if no one's has problems with it. Note that this class cannot decode base64 messages! base64 creates from 3 8-bit characters, 4 6-bit characters. That's why the output of base64 messages is 33% bigger than the original message.. But use the base64 (remember that the '='-sign is only used for padding) character set (0-9 A-Z a-z + /) and fool the world ;-) -- With best regards, Dave Mertens - Senior Development Manager dmertens@ism.nl Innovative Solutions in Media Schiekade 101 3033 BG Rotterdam, Netherlands T +31-10-2436060 F +31-10-2436066 http://www.ism.nl Quality Solutions - Reliable Partner

« previous php.pear.dev (#11431) next »