[Ircphpstats-devel] [CVS] Module phpstats: Change committed
Status: Inactive
Brought to you by:
mrvolta
From: Mr. v. <mr...@us...> - 2003-05-13 19:33:29
|
Committer : volta <mr...@us...> CVSROOT : /cvsroot/ircphpstats Module : phpstats Commit time: 2003-05-13 19:33:28 UTC Modified files: base64.php Log message: New ircu-like base64 algorithm. ---------------------- diff included ---------------------- Index: phpstats/base64.php diff -u phpstats/base64.php:1.1 phpstats/base64.php:1.2 --- phpstats/base64.php:1.1 Sun Mar 9 13:37:24 2003 +++ phpstats/base64.php Tue May 13 12:33:16 2003 @@ -5,77 +5,59 @@ E-mail: <vo...@gm...> This program is free but copyrighted software; see the file LICENSE for details. - $Id: base64.php,v 1.1 2003/03/09 21:37:24 mrvolta Exp $ + $Id: base64.php,v 1.2 2003/05/13 19:33:16 mrvolta Exp $ */ $a = 1; $convert2y = array( - 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P', - 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f', - 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', - 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','[',']' + 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P', + 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f', + 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', + 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','[',']' ); -// Need that simple convertion because each() doesn't like strings (which are -// actually arrays of chars), blame php -function string2array ($string) { - $i = 0; - while($string[$i]) { - $array[$i] = $string[$i]; - $i++; - }; - return $array; -}; +$convert2n = array( + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 52,53,54,55,56,57,58,59,60,61, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14, + 15,16,17,18,19,20,21,22,23,24,25,62, 0,63, 0, 0, + 0,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, + 41,42,43,44,45,46,47,48,49,50,51, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +); -// Idea from quakenet's L source +// Original functions from ircu function base64toint ($base64) { - $base64 = string2array($base64); + global $convert2n; $a = 0; - $n = 0; - while(list($key,$val) = each($base64)) { - $b = 0; - $asc_base64 = ord($val); - if (($asc_base64 >= 65) && ($asc_base64 <=90)) - $b = $asc_base64 - 65; - elseif (($asc_base64 >= 48) && ($asc_base64 <= 57)) - $b = $asc_base64 + 4; - elseif (($asc_base64 >= 97) && ($asc_base64 <= 122)) - $b = $asc_base64 - 71; - elseif ("]" == $val) - $b = 63; - elseif ("[" == $val) - $b = 62; - $a += $b * pow(64,(count($base64) - 1 - $n++)); + $i = $convert2n[ord($base64[$a++])]; + while ($base64[$a]) { + $i = $i << 6; + $i += $convert2n[ord($base64[$a++])]; }; - return $a; + return $i; }; -// Idea also from qnet's L function inttobase64 ($number,$count) { + global $convert2y; while ($count > 0) { - $number2 = $number % (64 ^ ($count - 1) - 1); - if (25 >= $number2) - $a = $number2 + 65; - elseif (51 >= $number2) - $a = $number2 + 71; - elseif (61 >= $number2) - $a = $number2 -4; - elseif (62 == $number2) - $a = 91; - elseif (63 == $number2) - $a = 93; - $number = $number / (64 ^ ($count - 1) - 1); - $array[$count--] = chr($a); - }; - $array = array_reverse($array); - $string = ""; - while (list($key,$val) = each($array)) { - $string = $string . $val; + $array[--$count] = $convert2y[($number & 63)]; + $number = $number >> 6; }; - return $string; + return implode("",array_reverse($array)); }; -// php's long2ip() is buggy, rather use this one from one of the notes in php's manual +// php's long2ip() is buggy, rather use this one from the notes in php's manual function mylong2ip($long) { if ($long > pow(2, 31)) $long -= pow(2, 32); @@ -86,5 +68,18 @@ if ($ip[$i] < 0) $ip[$i] += 256; } return join(".", $ip); +}; + +/* + This simple convertion is needed because each() doesn't like strings (which are + actually arrays of chars/strings). Blame php +*/ +function string2array ($string) { + $i = 0; + while($string[$i]) { + $array[$i] = $string[$i]; + $i++; + }; + return $array; }; ?> ----------------------- End of diff ----------------------- |