2 /******************************* PHP-P10 v2 *****************************
3 * Copyright (C) 2011-2012 Philipp Kreil (pk910) *
5 * This program is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 ************************************************************************
20 * Uplink/Numerics.class.php
22 * P10 numeric functions
27 private static $base64chars = array(
28 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
29 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
30 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
31 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','[',']'
33 private static $base64charsLength = 64;
35 public static function intToNum($int, $length) {
37 for($pos = $length-1; $pos >= 0; $pos--) {
38 //current position represents floor($int / ($base64charsLength ^ $pos))
40 for($i = 0; $i < $pos; $i++) {
41 $base = $base * self::$base64charsLength;
43 $posValue = floor($int / $base);
44 $int -= $posValue * $base;
45 //get the char representing $posValue
46 $posChar = self::$base64chars[$posValue];
53 public static function numToInt($numeric) {
56 for($pos = strlen($numeric)-1; $pos >= 0; $pos--) {
57 $posValue = array_search($numeric[$pos], self::$base64chars);
58 $int = ($posValue * $base);
59 $base = $base * self::$base64charsLength;