当前位置: 首页>>代码示例>>PHP>>正文


PHP Math_BigInteger类代码示例

本文整理汇总了PHP中Math_BigInteger的典型用法代码示例。如果您正苦于以下问题:PHP Math_BigInteger类的具体用法?PHP Math_BigInteger怎么用?PHP Math_BigInteger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Math_BigInteger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: add1

 public function add1($pos, $value, $sid)
 {
     if ($pos < $this->size()) {
         $tmp1 = new Math_BigInteger($this->get($pos)->getInt());
         $tmp = $tmp1->add($value);
         unset($this->mPosition[$pos]);
         $this->mPosition[$pos] = new LogootId($tmp->toString(), $sid);
     } else {
         $this->mPosition[] = new LogootId($tmp->toString(), $sid);
     }
 }
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:11,代码来源:LogootPosition.php

示例2: ssh1_connect

function ssh1_connect($host, $port)
{
    $identifier = 'SSH-1.5-' . basename(__FILE__);
    $fsock = fsockopen($host, $port, $errno, $errstr, 10);
    if (!$fsock) {
        die("Error {$errno}: {$errstr}");
    }
    $init_line = fgets($fsock, 255);
    if (!preg_match('#SSH-([0-9\\.]+)-(.+)#', $init_line, $parts)) {
        die('Not an SSH server on the other side.');
    }
    if ($parts[1][0] != 1) {
        die("SSH version {$parts[1]} is not supported!");
    }
    echo "Connecting to {$init_line}\r\n";
    fputs($fsock, "{$identifier}\n");
    $packet = get_binary_packet($fsock);
    if ($packet['type'] != SSH_SMSG_PUBLIC_KEY) {
        die('Expected SSH_SMSG_PUBLIC_KEY!');
    }
    $anti_spoofing_cookie = string_shift($packet['data'], 8);
    string_shift($packet['data'], 4);
    $temp = unpack('nlen', string_shift($packet['data'], 2));
    $server_key_public_exponent = new Math_BigInteger(string_shift($packet['data'], ceil($temp['len'] / 8)), 256);
    $temp = unpack('nlen', string_shift($packet['data'], 2));
    $server_key_public_modulus = new Math_BigInteger(string_shift($packet['data'], ceil($temp['len'] / 8)), 256);
    $temp = unpack('nlen', string_shift($packet['data'], 2));
    $host_key_public_exponent = new Math_BigInteger(string_shift($packet['data'], ceil($temp['len'] / 8)), 256);
    $temp = unpack('nlen', string_shift($packet['data'], 2));
    $host_key_public_modulus = new Math_BigInteger(string_shift($packet['data'], ceil($temp['len'] / 8)), 256);
    $session_id = pack('H*', md5($host_key_public_modulus . $server_key_public_modulus . $anti_spoofing_cookie));
    // ought to use a cryptographically secure random number generator (which mt_srand is not)
    list($sec, $usec) = explode(' ', microtime());
    mt_srand((double) $sec + (double) $usec * 100000);
    $session_key = '';
    for ($i = 0; $i < 32; $i++) {
        $session_key .= chr(mt_rand(0, 255));
    }
    $double_encrypted_session_key = $session_key ^ str_pad($session_id, 32, chr(0));
    echo "starting rsa encryption\r\n\r\n";
    if ($server_key_public_modulus->compare($host_key_public_modulus) < 0) {
        $prepped_key = prep_session_key($double_encrypted_session_key, $server_key_public_modulus);
        rsa_crypt($prepped_key, array($server_key_public_exponent, $server_key_public_modulus));
        rsa_crypt2($prepped_key, array($server_key_public_exponent, $server_key_public_modulus));
    } else {
        $prepped_key = prep_session_key($double_encrypted_session_key, $host_key_public_modulus);
        rsa_crypt($prepped_key, array($host_key_public_exponent, $host_key_public_modulus));
        rsa_crypt2($prepped_key, array($host_key_public_exponent, $host_key_public_modulus));
    }
}
开发者ID:quangbt2005,项目名称:vhost-kis,代码行数:50,代码来源:ssh_demo.php

示例3: inet_itop

 /**
  * @param string $decimal 128bit int
  * @return string IPv4 or IPv6
  */
 public static function inet_itop($decimal)
 {
     // QuickFix: Decimal 0 is both for ::0 and 0.0.0.0, however it defaults to IPv6, while there is now way a
     // ::/64 will ever be used.
     if ($decimal < 255) {
         return '0.0.0.' . $decimal;
     }
     $parts = array();
     // Use BCMath if available
     if (function_exists('bcadd')) {
         $parts[1] = bcdiv($decimal, '79228162514264337593543950336', 0);
         $decimal = bcsub($decimal, bcmul($parts[1], '79228162514264337593543950336'));
         $parts[2] = bcdiv($decimal, '18446744073709551616', 0);
         $decimal = bcsub($decimal, bcmul($parts[2], '18446744073709551616'));
         $parts[3] = bcdiv($decimal, '4294967296', 0);
         $decimal = bcsub($decimal, bcmul($parts[3], '4294967296'));
         $parts[4] = $decimal;
     } else {
         // Otherwise use the pure PHP BigInteger class
         $decimal = new Math_BigInteger($decimal);
         list($parts[1], ) = $decimal->divide(new Math_BigInteger('79228162514264337593543950336'));
         $decimal = $decimal->subtract($parts[1]->multiply(new Math_BigInteger('79228162514264337593543950336')));
         list($parts[2], ) = $decimal->divide(new Math_BigInteger('18446744073709551616'));
         $decimal = $decimal->subtract($parts[2]->multiply(new Math_BigInteger('18446744073709551616')));
         list($parts[3], ) = $decimal->divide(new Math_BigInteger('4294967296'));
         $decimal = $decimal->subtract($parts[3]->multiply(new Math_BigInteger('4294967296')));
         $parts[4] = $decimal;
         $parts[1] = $parts[1]->toString();
         $parts[2] = $parts[2]->toString();
         $parts[3] = $parts[3]->toString();
         $parts[4] = $parts[4]->toString();
     }
     foreach ($parts as &$part) {
         // convert any signed ints to unsigned for pack
         // this should be fine as it will be treated as a float
         if ($part > 2147483647) {
             $part -= 4294967296.0;
         }
     }
     $ip = inet_ntop(pack('N4', $parts[1], $parts[2], $parts[3], $parts[4]));
     // fix IPv4 by removing :: from the beginning
     if (strpos($ip, '.') !== false) {
         return substr($ip, 2);
     }
     return $ip;
 }
开发者ID:nielstholenaar,项目名称:AbuseIO,代码行数:50,代码来源:Functions.php

示例4: make64Int

 protected static function make64Int($hi, $lo)
 {
     if (PHP_INT_SIZE > 4) {
         return (int) $hi << 32 | (int) $lo;
     }
     $lo = sprintf("%u", $lo);
     if (function_exists("gmp_mul")) {
         return gmp_strval(gmp_add(gmp_mul($hi, "4294967296"), $lo));
     }
     if (function_exists("bcmul")) {
         return bcadd(bcmul($hi, "4294967296"), $lo);
     }
     if (class_exists('Math_BigInteger')) {
         $bi = new Math_BigInteger($hi);
         return $bi->multiply("4294967296")->add($lo)->toString();
     }
     throw new PListException("either gmp or bc has to be installed, or the Math_BigInteger has to be available!");
 }
开发者ID:robextrem,项目名称:testgrid,代码行数:18,代码来源:CFBinaryPropertyList.php

示例5: decrypt

function decrypt($val)
{
    # Support for both obfuscated and unobfuscated passwords
    $encryptionstr = 'Encrypted ';
    if (strstr($val, $encryptionstr)) {
        $val = substr($val, strlen($encryptionstr));
    } else {
        return $val;
    }
    # decryption logic
    $decconst = new Math_BigInteger('933910847463829827159347601486730416058');
    $decrparam = new Math_BigInteger($val, 16);
    $decryptedval = $decrparam->bitwise_xor($decconst)->toBytes();
    $result = "";
    for ($i = 0; $i < strlen($decryptedval); $i = $i + 1) {
        $result .= $decryptedval[$i];
    }
    return $result;
}
开发者ID:EfncoPlugins,项目名称:Media-Management-based-on-Kaltura,代码行数:19,代码来源:pentaho_decrypt.php

示例6: compareTo

 public function compareTo($id)
 {
     $logid = $id;
     $val1 = new Math_BigInteger($this->mInt);
     $val2 = new Math_BigInteger($logid->mInt);
     if ($val1->compare($val2) < 0) {
         return -1;
     } else {
         if ($val1->compare($val2) > 0) {
             return 1;
         } else {
             if (strcmp($this->mSessionId, $logid->mSessionId) < 0) {
                 return -1;
             } else {
                 if (strcmp($this->mSessionId, $logid->mSessionId) > 0) {
                     return 1;
                 }
             }
         }
     }
     return 0;
 }
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:22,代码来源:LogootId.php

示例7: inetPtoi

/**
 * @param string $ip IPv4 or IPv6 address to convert
 *
 * @return string 128bit string that can be used with DECIMNAL(39,0) or false
 */
function inetPtoi($ip)
{
    // make sure it is an ip
    if (filter_var($ip, FILTER_VALIDATE_IP) === false) {
        return false;
    }
    $parts = unpack('N*', inet_pton($ip));
    // fix IPv4
    if (strpos($ip, '.') !== false) {
        $parts = [1 => 0, 2 => 0, 3 => 0, 4 => $parts[1]];
    }
    foreach ($parts as &$part) {
        // convert any unsigned ints to signed from unpack.
        // this should be OK as it will be a PHP float not an int
        if ($part < 0) {
            $part = 4294967296;
        }
    }
    if (function_exists('bcadd')) {
        // Use BCMath if available
        $decimal = $parts[4];
        $decimal = bcadd($decimal, bcmul($parts[3], '4294967296'));
        $decimal = bcadd($decimal, bcmul($parts[2], '18446744073709551616'));
        $decimal = bcadd($decimal, bcmul($parts[1], '79228162514264337593543950336'));
    } else {
        // Otherwise use the pure PHP BigInteger class
        $decimal = new Math_BigInteger($parts[4]);
        $partTree = new Math_BigInteger($parts[3]);
        $partTwo = new Math_BigInteger($parts[2]);
        $partOne = new Math_BigInteger($parts[1]);
        $decimal = $decimal->add($partTree->multiply(new Math_BigInteger('4294967296')));
        $decimal = $decimal->add($partTwo->multiply(new Math_BigInteger('18446744073709551616')));
        $decimal = $decimal->add($partOne->multiply(new Math_BigInteger('79228162514264337593543950336')));
        $decimal = $decimal->toString();
    }
    return $decimal;
}
开发者ID:ihatehandles,项目名称:AbuseIO,代码行数:42,代码来源:inetPtoi.php

示例8: bitwise_xor

 /**
  * Logical Exclusive-Or
  *
  * @param Math_BigInteger $x
  * @access public
  * @internal Implemented per a request by Lluis Pamies i Juarez <lluis _a_ pamies.cat>
  * @return Math_BigInteger
  */
 function bitwise_xor($x)
 {
     switch (MATH_BIGINTEGER_MODE) {
         case MATH_BIGINTEGER_MODE_GMP:
             $temp = new Math_BigInteger();
             $temp->value = gmp_xor($this->value, $x->value);
             return $temp;
         case MATH_BIGINTEGER_MODE_BCMATH:
             return new Math_BigInteger($this->toBytes() ^ $x->toBytes(), 256);
     }
     $result = new Math_BigInteger();
     $x_length = count($x->value);
     for ($i = 0; $i < $x_length; $i++) {
         $result->value[] = $this->value[$i] ^ $x->value[$i];
     }
     return $result->_normalize();
 }
开发者ID:thu0ng91,项目名称:jmc,代码行数:25,代码来源:biginteger.php

示例9: randomPrime

 /**
  * Generate a random prime number.
  *
  * If there's not a prime within the given range, false will be returned.  If more than $timeout seconds have elapsed,
  * give up and return false.
  *
  * @param optional Integer $min
  * @param optional Integer $max
  * @param optional Integer $timeout
  * @return Math_BigInteger
  * @access public
  * @internal See {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap4.pdf#page=15 HAC 4.44}.
  */
 function randomPrime($min = false, $max = false, $timeout = false)
 {
     // gmp_nextprime() requires PHP 5 >= 5.2.0 per <http://php.net/gmp-nextprime>.
     if (MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_GMP && function_exists('gmp_nextprime')) {
         // we don't rely on Math_BigInteger::random()'s min / max when gmp_nextprime() is being used since this function
         // does its own checks on $max / $min when gmp_nextprime() is used.  When gmp_nextprime() is not used, however,
         // the same $max / $min checks are not performed.
         if ($min === false) {
             $min = new Math_BigInteger(0);
         }
         if ($max === false) {
             $max = new Math_BigInteger(0x7fffffff);
         }
         $compare = $max->compare($min);
         if (!$compare) {
             return $min;
         } else {
             if ($compare < 0) {
                 // if $min is bigger then $max, swap $min and $max
                 $temp = $max;
                 $max = $min;
                 $min = $temp;
             }
         }
         $x = $this->random($min, $max);
         $x->value = gmp_nextprime($x->value);
         if ($x->compare($max) <= 0) {
             return $x;
         }
         $x->value = gmp_nextprime($min->value);
         if ($x->compare($max) <= 0) {
             return $x;
         }
         return false;
     }
     $repeat1 = $repeat2 = array();
     $one = new Math_BigInteger(1);
     $two = new Math_BigInteger(2);
     $start = time();
     do {
         if ($timeout !== false && time() - $start > $timeout) {
             return false;
         }
         $x = $this->random($min, $max);
         if ($x->equals($two)) {
             return $x;
         }
         // make the number odd
         switch (MATH_BIGINTEGER_MODE) {
             case MATH_BIGINTEGER_MODE_GMP:
                 gmp_setbit($x->value, 0);
                 break;
             case MATH_BIGINTEGER_MODE_BCMATH:
                 if ($x->value[strlen($x->value) - 1] % 2 == 0) {
                     $x = $x->add($one);
                 }
                 break;
             default:
                 $x->value[0] |= 1;
         }
         // if we've seen this number twice before, assume there are no prime numbers within the given range
         if (in_array($x->value, $repeat1)) {
             if (in_array($x->value, $repeat2)) {
                 return false;
             } else {
                 $repeat2[] = $x->value;
             }
         } else {
             $repeat1[] = $x->value;
         }
     } while (!$x->isPrime());
     return $x;
 }
开发者ID:helenadeus,项目名称:s3db.map,代码行数:86,代码来源:BigInteger.php

示例10: verify

 /**
  * DSA verify.
  *
  * @param string $message     Message.
  * @param string $hash_alg    Hash algorithm.
  * @param Math_BigInteger $r  r.
  * @param Math_BigInteger $s  s.
  *
  * @return bool  True if verified.
  */
 public function verify($message, $hash_alg, $r, $s)
 {
     $hash = new Crypt_Hash($hash_alg);
     $hash_m = new Math_BigInteger($hash->hash($message), 256);
     $g = new Math_BigInteger($this->_key->key['g'], 256);
     $p = new Math_BigInteger($this->_key->key['p'], 256);
     $q = new Math_BigInteger($this->_key->key['q'], 256);
     $y = new Math_BigInteger($this->_key->key['y'], 256);
     $w = $s->modInverse($q);
     $hash_m_mul = $hash_m->multiply($w);
     $u1_base = $hash_m_mul->divide($q);
     $u1 = $u1_base[1];
     $r_mul = $r->multiply($w);
     $u2_base = $r_mul->divide($q);
     $u2 = $u2_base[1];
     $g_pow = $g->modPow($u1, $p);
     $y_pow = $y->modPow($u2, $p);
     $g_pow_mul = $g_pow->multiply($y_pow);
     $g_pow_mul_mod_base = $g_pow_mul->divide($p);
     $g_pow_mul_mod = $g_pow_mul_mod_base[1];
     $v_base = $g_pow_mul_mod->divide($q);
     $v = $v_base[1];
     return $v->compare($r) == 0;
 }
开发者ID:raz0rsdge,项目名称:horde,代码行数:34,代码来源:DSA.php

示例11: mysqli_query

 if ($timestampDifference < 8) {
     $newTimeRange = $min_timestamp - 60 * 8;
     $existQuery = "SELECT address,minerdiff,blockdiff,time FROM shares_history WHERE time > {$newTimeRange}";
     $existResultMinersss = mysqli_query($mysqli, $existQuery) or die("Database Error");
     $count_response = mysqli_num_rows($existResultMinersss);
     echo "\nShares_OLD_Taken:" . $count_response . '';
     $current .= "\nShares_OLD_Taken:" . $count_response . '';
     while ($row = mysqli_fetch_row($existResultMinersss)) {
         $miner_adr = $row[0];
         $miner_adr_balance = new Math_BigInteger($row[1]);
         $totalMinersDiff = $totalMinersDiff->add($miner_adr_balance);
         if (!isset($miner_payouts["'{$miner_adr}'"])) {
             $miner_payouts["'{$miner_adr}'"] = $miner_adr_balance;
             $old_new_added++;
         } else {
             $miner_adr_balance_fromArray = new Math_BigInteger($miner_payouts["'{$miner_adr}'"]);
             $setNewValue = $miner_adr_balance_fromArray->add($miner_adr_balance);
             $miner_payouts["'{$miner_adr}'"] = $setNewValue->toString();
             $old_old_old++;
         }
     }
     echo "\nShares_OLD_Taken__NEWADDED:" . $old_new_added . '';
     $current .= "\nShares_OLD_Taken__NEWADDED:" . $old_new_added . '';
     echo "\nShares_OLD_Taken__OLD_SUMMARY:" . $old_old_old . '';
     $current .= "\nShares_OLD_Taken__OLD_SUMMARY:" . $old_old_old . '';
 }
 echo "\n=============================================================================";
 echo "\nTotal Miners Diff:" . $totalMinersDiff->toString() . '  =  ' . $block_coins_size->toString() . ' wei';
 $current .= "\n=============================================================================";
 $current .= "\nTotal Miners Diff:" . $totalMinersDiff->toString() . '  =  ' . $block_coins_size->toString() . ' wei';
 $totalsplit = new Math_BigInteger(0);
开发者ID:cpplover,项目名称:Ethereumpool.co---Ethereum-Mining-Pool-Full-Source,代码行数:31,代码来源:index.php

示例12: random

 /**
  * Generate a random number
  *
  * @param optional Integer $min
  * @param optional Integer $max
  * @return Math_BigInteger
  * @access public
  */
 function random($min = false, $max = false)
 {
     if ($min === false) {
         $min = new Math_BigInteger(0);
     }
     if ($max === false) {
         $max = new Math_BigInteger(0x7fffffff);
     }
     $compare = $max->compare($min);
     if (!$compare) {
         return $this->_normalize($min);
     } else {
         if ($compare < 0) {
             // if $min is bigger then $max, swap $min and $max
             $temp = $max;
             $max = $min;
             $min = $temp;
         }
     }
     $generator = $this->generator;
     $max = $max->subtract($min);
     $max = ltrim($max->toBytes(), chr(0));
     $size = strlen($max) - 1;
     $crypt_random = function_exists('crypt_random_string') || !class_exists('Crypt_Random') && function_exists('crypt_random_string');
     if ($crypt_random) {
         $random = crypt_random_string($size);
     } else {
         $random = '';
         if ($size & 1) {
             $random .= chr(mt_rand(0, 255));
         }
         $blocks = $size >> 1;
         for ($i = 0; $i < $blocks; ++$i) {
             // mt_rand(-2147483648, 0x7FFFFFFF) always produces -2147483648 on some systems
             $random .= pack('n', mt_rand(0, 0xffff));
         }
     }
     $fragment = new Math_BigInteger($random, 256);
     $leading = $fragment->compare(new Math_BigInteger(substr($max, 1), 256)) > 0 ? ord($max[0]) - 1 : ord($max[0]);
     if (!$crypt_random) {
         $msb = chr(mt_rand(0, $leading));
     } else {
         $cutoff = floor(0xff / $leading) * $leading;
         while (true) {
             $msb = ord(crypt_random_string(1));
             if ($msb <= $cutoff) {
                 $msb %= $leading;
                 break;
             }
         }
         $msb = chr($msb);
     }
     $random = new Math_BigInteger($msb . $random, 256);
     return $this->_normalize($random->add($min));
 }
开发者ID:omusico,项目名称:isle-web-framework,代码行数:63,代码来源:BigInteger.php

示例13:

 /**
  * RSAVP1
  *
  * See {@link http://tools.ietf.org/html/rfc3447#section-5.2.2 RFC3447#section-5.2.2}.
  *
  * @access private
  * @param Math_BigInteger $s
  * @return Math_BigInteger
  */
 function _rsavp1($s)
 {
     if ($s->compare($this->zero) < 0 || $s->compare($this->modulus) > 0) {
         user_error('Signature representative out of range', E_USER_NOTICE);
         return false;
     }
     return $this->_exponentiate($s);
 }
开发者ID:microcosmx,项目名称:experiments,代码行数:17,代码来源:RSA.php

示例14: _revokedCertificate

 /**
  * Get the index of a revoked certificate.
  *
  * @param array $rclist        	
  * @param String $serial        	
  * @param Boolean $create
  *        	optional
  * @access private
  * @return Integer or false
  */
 function _revokedCertificate(&$rclist, $serial, $create = false)
 {
     $serial = new Math_BigInteger($serial);
     foreach ($rclist as $i => $rc) {
         if (!$serial->compare($rc['userCertificate'])) {
             return $i;
         }
     }
     if (!$create) {
         return false;
     }
     $i = count($rclist);
     $rclist[] = array('userCertificate' => $serial, 'revocationDate' => $this->_timeField(@date('D, d M Y H:i:s O')));
     return $i;
 }
开发者ID:K0smas,项目名称:Doulci-master,代码行数:25,代码来源:X509.php

示例15: getLogootPosition

 /**
  * generation of a position, logoot algorithm
  * @param <LogootPosition> $p is the previous logootPosition
  * @param <LogootPosition> $q is the next logootPosition
  * @param $N number of positions generated (should be 1 in our case)
  * @param <Integer> $rep_sid session id
  * @param <Integer> $rep_clock session clock
  * @param $boundary Cf. method
  * @return <LogootPosition List> $N logootPosition(s) between $start and $end
  */
 public static function getLogootPosition(LogootPosition $p, LogootPosition $q, $nb, $rep_sid, $rep_clock = 0, $boundary = NULL)
 {
     wfDebugLog('p2p', $rep_clock . " - function LogootPosition::getLogootPosition " . $p . " / " . $q . " pour " . $nb . " position(s)");
     $one = new Math_BigInteger("1");
     // Recherche de l'interval optimal
     $index = 0;
     $interval = INT_MIN;
     $size = max($p->size(), $q->size()) + 1;
     $prefix_p = array(0 => array('cum_val' => "", 'id_str_val' => ""));
     $prefix_q = array(0 => array('cum_val' => "", 'id_str_val' => ""));
     while ($interval < $nb) {
         $index += 1;
         // recherche de prefix($p, index);
         if ($index <= $p->size()) {
             $str_val_p = str_pad($p->get($index - 1)->getInt(), DIGIT, "0", STR_PAD_LEFT);
         } else {
             $str_val_p = LPINTMINDIGIT;
         }
         $prefix_p[$index] = array('id_str_val' => $str_val_p, 'cum_val' => $prefix_p[$index - 1]['cum_val'] . $str_val_p);
         // recherche de prefix($p, index);
         if ($index <= $q->size()) {
             $str_val_q = str_pad($q->get($index - 1)->getInt(), DIGIT, "0", STR_PAD_LEFT);
         } else {
             $str_val_q = LPINTMINDIGIT;
         }
         $prefix_q[$index] = array('id_str_val' => $str_val_q, 'cum_val' => $prefix_q[$index - 1]['cum_val'] . $str_val_q);
         // Calcul de l'interval sur les nouveaux prefixes
         $BI_p = new Math_BigInteger($prefix_p[$index]['cum_val']);
         $BI_q = new Math_BigInteger($prefix_q[$index]['cum_val']);
         $BIinterval = $BI_q->subtract($BI_p)->subtract($one);
         $interval = (int) $BIinterval->__toString();
         /*wfDebugLog('p2p', $index
           . " : Prefix_p " . (string) $prefix_p[$index]['cum_val'] . '/'
           . $prefix_p[$index]['id_str_val']
           . " Prefix_q " . (string) $prefix_q[$index]['cum_val'] . '/'
           . $prefix_q[$index]['id_str_val']
           . " Interval " . $interval);*/
     }
     // Construction des identifiants
     //wfDebugLog('p2p', "N " . $nb . " Interval " . $interval . " index " . $index);
     $step = (int) $interval / $nb;
     if (isset($boundary)) {
         $step = $boundary < $step ? $boundary : $step;
     }
     $BI_step = new Math_BigInteger($step);
     $BI_r = new Math_BigInteger($prefix_p[$index]['cum_val']);
     $list = array();
     //wfDebugLog('p2p', "Step :" . $step . "/" . $boundary);
     for ($j = 1; $j <= $nb; $j++) {
         $BI_nr = $BI_r->add(new Math_BigInteger(rand(1, $step)));
         //wfDebugLog('p2p', "nr " . (string) $BI_nr . " r " . (string) $BI_r);
         // pour découper une chaine en paquets de N car : str_split($cdc, $N) !
         $str_nr0 = (string) $BI_nr;
         // on fait en sorte que le découpage soit un multiple de DIGIT pour ne pas créer de décallage
         if (strlen($str_nr0) % ($index * DIGIT) != 0) {
             $str_nr = str_pad($str_nr0, strlen($str_nr0) + ($index * DIGIT - strlen($str_nr0) % ($index * DIGIT)), "0", STR_PAD_LEFT);
         } else {
             $str_nr = $str_nr0;
         }
         //wfDebugLog('p2p', "str_nr0 " . $str_nr0 . " str_nr " . $str_nr);
         $tab_nr = str_split($str_nr, DIGIT);
         $pos = new LogootPosition();
         for ($i = 1; $i <= count($tab_nr); $i++) {
             $d = $tab_nr[$i - 1];
             //wfDebugLog('p2p', "$i#" . $prefix_p[$i]['id_str_val'] . "#" . $prefix_q[$i]['id_str_val'] . "#" . $d);
             if ($i <= $p->size() && $prefix_p[$i]['id_str_val'] == $d) {
                 $id = new LogootId($d, $p->get($i - 1)->getSessionId(), $p->get($i - 1)->getClock());
             } elseif ($i <= $q->size() && $prefix_q[$i]['id_str_val'] == $d) {
                 $id = new LogootId($d, $q->get($i - 1)->getSessionId(), $q->get($i - 1)->getClock());
             } else {
                 $id = new LogootId($d, $rep_sid, $rep_clock);
             }
             $pos->addId($id);
         }
         wfDebugLog('p2p', "===========>" . $pos->__toString());
         $list[] = $pos;
         $BI_r = $BI_r->add($BI_step);
     }
     return $list;
 }
开发者ID:hala54,项目名称:DSMW,代码行数:90,代码来源:LogootPosition.php


注:本文中的Math_BigInteger类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。