Public paste
Base64 ip's to decimal
By: Arie | Date: Aug 25 2006 12:44 | Format: PHP | Expires: never | Size: 1.29 KB | Hits: 1721

  1.     private function IPbase64ToDecimal($base64)
  2.     {
  3.         $ip = $this->base64Todecimal($base64);
  4.         $iphex = dechex($ip);
  5.         $part0 = substr($iphex,0,2);
  6.         $part0 = hexdec($part0);
  7.        
  8.         $part1 = substr($iphex,2,2);
  9.         $part1 = hexdec($part1);
  10.        
  11.         $part2 = substr($iphex,4,2);
  12.         $part2 = hexdec($part2);
  13.        
  14.         $part3 = substr($iphex,6,2);
  15.         $part3 = hexdec($part3);
  16.         return $part0 . "." . $part1 . "." . $part2 . "." . $part3;
  17.     }
  18.  
  19.    
  20.     private function base64Todecimal($Base64)
  21.     {
  22.         $b64chars = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
  23.         'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b',
  24.         'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
  25.         'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3',
  26.         '4', '5', '6', '7', '8', '9', '[', ']');
  27.         for ($i = 0; $i < strlen($Base64); $i++)
  28.         {
  29.             $cur = $Base64{$i};
  30.             for ($j = 0; $j < 64; $j++)
  31.                 if ($b64chars[$j] == $cur) $num = $j;
  32.             $pow = strlen($Base64) - $i - 1;
  33.             $pow = pow(64,$pow);
  34.             $result += $num * $pow;
  35.         }
  36.         return $result;
  37.     }