本文整理汇总了PHP中Math_BigInteger类的典型用法代码示例。如果您正苦于以下问题:PHP Math_BigInteger类的具体用法?PHP Math_BigInteger怎么用?PHP Math_BigInteger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Math_BigInteger类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: mt_rand
<?php
// $Id$
// Example of how to use of BigInteger. The output can be compared to the output that the BCMath functions would yield.
// bcpowmod is included with Math_BigInteger.php via PHP_Compat.
require __DIR__ . '/../vendor/autoload.php';
$x = mt_rand(1, 10000000);
$y = mt_rand(1, 10000000);
$z = mt_rand(1, 10000000);
$_x = new Math_BigInteger($x);
$_y = new Math_BigInteger($y);
$_z = new Math_BigInteger($z);
echo "\$x = {$x};\r\n";
echo "\$y = {$y};\r\n";
echo "\$z = {$z};\r\n";
echo "\r\n";
$result = bcadd($x, $y);
$_result = $_x->add($_y);
echo "\$result = \$x+\$y;\r\n";
echo "{$result}\r\n";
echo $_result->toString();
echo "\r\n\r\n";
$result = bcsub($result, $y);
$_result = $_result->subtract($_y);
echo "\$result = \$result-\$y;\r\n";
echo "{$result}\r\n";
echo $_result->toString();
echo "\r\n\r\n";
$result = bcdiv($x, $y);
list($_result, ) = $_x->divide($_y);
echo "\$result = \$x/\$y;\r\n";
开发者ID:carlcs,项目名称:craft-helpers,代码行数:31,代码来源:demo.php
示例17: make64Int
/**
* Create an 64 bit integer using bcmath or gmp
* @param int $hi The higher word
* @param int $lo The lower word
* @return mixed The integer (as int if possible, as string if not possible)
* @throws PListException if neither gmp nor bc available
*/
protected static function make64Int($hi, $lo)
{
// on x64, we can just use int
if (PHP_INT_SIZE > 4) {
return (int) $hi << 32 | (int) $lo;
}
// lower word has to be unsigned since we don't use bitwise or, we use bcadd/gmp_add
$lo = sprintf("%u", $lo);
// use GMP or bcmath if possible
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(new \Math_BigInteger("4294967296"))->add(new \Math_BigInteger($lo))->toString();
}
throw new PListException("either gmp or bc has to be installed, or the Math_BigInteger has to be available!");
}
开发者ID:vb2005xu,项目名称:CFPropertyList,代码行数:28,代码来源:CFBinaryPropertyList.php
示例18: 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;
$random = '';
$bytes = $size & 1;
for ($i = 0; $i < $bytes; ++$i) {
$random .= chr($generator(0, 255));
}
$blocks = $size >> 1;
for ($i = 0; $i < $blocks; ++$i) {
// mt_rand(-2147483648, 0x7FFFFFFF) always produces -2147483648 on some systems
$random .= pack('n', $generator(0, 0xffff));
}
$temp = new Math_BigInteger($random, 256);
if ($temp->compare(new Math_BigInteger(substr($max, 1), 256)) > 0) {
$random = chr($generator(0, ord($max[0]) - 1)) . $random;
} else {
$random = chr($generator(0, ord($max[0]))) . $random;
}
$random = new Math_BigInteger($random, 256);
return $this->_normalize($random->add($min));
}
开发者ID:katopenzz,项目名称:openemr,代码行数:50,代码来源:BigInteger.php
示例19: 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)
{
if ($min === false) {
$min = new Math_BigInteger(0);
}
if ($max === false) {
$max = new Math_BigInteger(0x7fffffff);
}
$compare = $max->compare($min);
if (!$compare) {
return $min->isPrime() ? $min : false;
} else {
if ($compare < 0) {
// if $min is bigger then $max, swap $min and $max
$temp = $max;
$max = $min;
$min = $temp;
}
}
static $one, $two;
if (!isset($one)) {
$one = new Math_BigInteger(1);
$two = new Math_BigInteger(2);
}
$start = time();
$x = $this->random($min, $max);
if ($x->equals($two)) {
return $x;
}
$x->_make_odd();
if ($x->compare($max) > 0) {
// if $x > $max then $max is even and if $min == $max then no prime number exists between the specified range
if ($min->equals($max)) {
return false;
}
$x = $min->copy();
$x->_make_odd();
}
$initial_x = $x->copy();
while (true) {
if ($timeout !== false && time() - $start > $timeout) {
return false;
}
if ($x->isPrime()) {
return $x;
}
$x = $x->add($two);
if ($x->compare($max) > 0) {
$x = $min->copy();
if ($x->equals($two)) {
return $x;
}
$x->_make_odd();
}
if ($x->equals($initial_x)) {
return false;
}
}
}
开发者ID:luzhongyang,项目名称:yeepay,代码行数:72,代码来源:Math_BigInteger.php
示例20: _sha512
/**
* Pure-PHP implementation of SHA384 and SHA512
*
* @access private
* @param String $text
*/
function _sha512($m)
{
if (!class_exists('Math_BigInteger')) {
require_once 'Math/BigInteger.php';
}
static $init384, $init512, $k;
if (!isset($k)) {
// Initialize variables
$init384 = array('cbbb9d5dc1059ed8', '629a292a367cd507', '9159015a3070dd17', '152fecd8f70e5939', '67332667ffc00b31', '8eb44a8768581511', 'db0c2e0d64f98fa7', '47b5481dbefa4fa4');
$init512 = array('6a09e667f3bcc908', 'bb67ae8584caa73b', '3c6ef372fe94f82b', 'a54ff53a5f1d36f1', '510e527fade682d1', '9b05688c2b3e6c1f', '1f83d9abfb41bd6b', '5be0cd19137e2179');
for ($i = 0; $i < 8; $i++) {
$init384[$i] = new Math_BigInteger($init384[$i], 16);
$init384[$i]->setPrecision(64);
$init512[$i] = new Math_BigInteger($init512[$i], 16);
$init512[$i]->setPrecision(64);
}
// Initialize table of round constants
// (first 64 bits of the fractional parts of the cube roots of the first 80 primes 2..409)
$k = array('428a2f98d728ae22', '7137449123ef65cd', 'b5c0fbcfec4d3b2f', 'e9b5dba58189dbbc', '3956c25bf348b538', '59f111f1b605d019', '923f82a4af194f9b', 'ab1c5ed5da6d8118', 'd807aa98a3030242', '12835b0145706fbe', '243185be4ee4b28c', '550c7dc3d5ffb4e2', '72be5d74f27b896f', '80deb1fe3b1696b1', '9bdc06a725c71235', 'c19bf174cf692694', 'e49b69c19ef14ad2', 'efbe4786384f25e3', '0fc19dc68b8cd5b5', '240ca1cc77ac9c65', '2de92c6f592b0275', '4a7484aa6ea6e483', '5cb0a9dcbd41fbd4', '76f988da831153b5', '983e5152ee66dfab', 'a831c66d2db43210', 'b00327c898fb213f', 'bf597fc7beef0ee4', 'c6e00bf33da88fc2', 'd5a79147930aa725', '06ca6351e003826f', '142929670a0e6e70', '27b70a8546d22ffc', '2e1b21385c26c926', '4d2c6dfc5ac42aed', '53380d139d95b3df', '650a73548baf63de', '766a0abb3c77b2a8', '81c2c92e47edaee6', '92722c851482353b', 'a2bfe8a14cf10364', 'a81a664bbc423001', 'c24b8b70d0f89791', 'c76c51a30654be30', 'd192e819d6ef5218', 'd69906245565a910', 'f40e35855771202a', '106aa07032bbd1b8', '19a4c116b8d2d0c8', '1e376c085141ab53', '2748774cdf8eeb99', '34b0bcb5e19b48a8', '391c0cb3c5c95a63', '4ed8aa4ae3418acb', '5b9cca4f7763e373', '682e6ff3d6b2b8a3', '748f82ee5defb2fc', '78a5636f43172f60', '84c87814a1f0ab72', '8cc702081a6439ec', '90befffa23631e28', 'a4506cebde82bde9', 'bef9a3f7b2c67915', 'c67178f2e372532b', 'ca273eceea26619c', 'd186b8c721c0c207', 'eada7dd6cde0eb1e', 'f57d4f7fee6ed178', '06f067aa72176fba', '0a637dc5a2c898a6', '113f9804bef90dae', '1b710b35131c471b', '28db77f523047d84', '32caab7b40c72493', '3c9ebe0a15c9bebc', '431d67c49c100d4c', '4cc5d4becb3e42b6', '597f299cfc657e2a', '5fcb6fab3ad6faec', '6c44198c4a475817');
for ($i = 0; $i < 80; $i++) {
$k[$i] = new Math_BigInteger($k[$i], 16);
}
}
$hash = $this->l == 48 ? $init384 : $init512;
// Pre-processing
$length = strlen($m);
// to round to nearest 112 mod 128, we'll add 128 - (length + (128 - 112)) % 128
$m .= str_repeat(chr(0), 128 - ($length + 16 & 0x7f));
$m[$length] = chr(0x80);
// we don't support hashing strings 512MB long
$m .= pack('N4', 0, 0, 0, $length << 3);
// Process the message in successive 1024-bit chunks
$chunks = str_split($m, 128);
foreach ($chunks as $chunk) {
$w = array();
for ($i = 0; $i < 16; $i++) {
$temp = new Math_BigInteger($this->_string_shift($chunk, 8), 256);
$temp->setPrecision(64);
$w[] = $temp;
}
// Extend the sixteen 32-bit words into eighty 32-bit words
for ($i = 16; $i < 80; $i++) {
$temp = array($w[$i - 15]->bitwise_rightRotate(1), $w[$i - 15]->bitwise_rightRotate(8), $w[$i - 15]->bitwise_rightShift(7));
$s0 = $temp[0]->bitwise_xor($temp[1]);
$s0 = $s0->bitwise_xor($temp[2]);
$temp = array($w[$i - 2]->bitwise_rightRotate(19), $w[$i - 2]->bitwise_rightRotate(61), $w[$i - 2]->bitwise_rightShift(6));
$s1 = $temp[0]->bitwise_xor($temp[1]);
$s1 = $s1->bitwise_xor($temp[2]);
$w[$i] = $w[$i - 16]->copy();
$w[$i] = $w[$i]->add($s0);
$w[$i] = $w[$i]->add($w[$i - 7]);
$w[$i] = $w[$i]->add($s1);
}
// Initialize hash value for this chunk
$a = $hash[0]->copy();
$b = $hash[1]->copy();
$c = $hash[2]->copy();
$d = $hash[3]->copy();
$e = $hash[4]->copy();
$f = $hash[5]->copy();
$g = $hash[6]->copy();
$h = $hash[7]->copy();
// Main loop
for ($i = 0; $i < 80; $i++) {
$temp = array($a->bitwise_rightRotate(28), $a->bitwise_rightRotate(34), $a->bitwise_rightRotate(39));
$s0 = $temp[0]->bitwise_xor($temp[1]);
$s0 = $s0->bitwise_xor($temp[2]);
$temp = array($a->bitwise_and($b), $a->bitwise_and($c), $b->bitwise_and($c));
$maj = $temp[0]->bitwise_xor($temp[1]);
$maj = $maj->bitwise_xor($temp[2]);
$t2 = $s0->add($maj);
$temp = array($e->bitwise_rightRotate(14), $e->bitwise_rightRotate(18), $e->bitwise_rightRotate(41));
$s1 = $temp[0]->bitwise_xor($temp[1]);
$s1 = $s1->bitwise_xor($temp[2]);
$temp = array($e->bitwise_and($f), $g->bitwise_and($e->bitwise_not()));
$ch = $temp[0]->bitwise_xor($temp[1]);
$t1 = $h->add($s1);
$t1 = $t1->add($ch);
$t1 = $t1->add($k[$i]);
$t1 = $t1->add($w[$i]);
$h = $g->copy();
$g = $f->copy();
$f = $e->copy();
$e = $d->add($t1);
$d = $c->copy();
$c = $b->copy();
$b = $a->copy();
|
请发表评论