本文整理汇总了PHP中gmp_mod函数的典型用法代码示例。如果您正苦于以下问题:PHP gmp_mod函数的具体用法?PHP gmp_mod怎么用?PHP gmp_mod使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gmp_mod函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: nextPrime
/**
* Finds next strong pseudoprime number, following after $num
*
* @param gmp resource $num
* @return gmp resource
* @access public
*/
function nextPrime($num)
{
if (!gmp_cmp(gmp_mod($num, 2), 0)) {
$num = gmp_sub($num, 1);
}
do {
$num = gmp_add($num, 2);
} while (!gmp_prob_prime($num));
return $num;
}
开发者ID:KICHIRO20,项目名称:-Myproject_part1-,代码行数:17,代码来源:GMP.php
示例2: testMod
public function testMod()
{
$this->assertEquals(gmp_strval(gmp_mod($this->a, $this->a)), $this->math->mod($this->a, $this->a));
$this->assertEquals(gmp_strval(gmp_mod($this->b, $this->b)), $this->math->mod($this->b, $this->b));
$this->assertEquals(gmp_strval(gmp_mod($this->c, $this->c)), $this->math->mod($this->c, $this->c));
$this->assertEquals(0, $this->math->mod(1, 1));
}
开发者ID:Invision70,项目名称:php-bitpay-client,代码行数:7,代码来源:GmpEngineTest.php
示例3: main
function main()
{
global $numEpochs;
global $numPatterns;
global $patNum;
global $RMSerror;
// initiate the weights
initWeights();
// load in the data
initData();
// train the network
for ($j = 0; $j <= $numEpochs; $j++) {
for ($i = 0; $i < $numPatterns; $i++) {
//select a pattern at random
//srand();
$patNum = rand(0, $numPatterns - 1);
//calculate the current network output
//and error for this pattern
calcNet();
//change network weights
WeightChangesHO();
WeightChangesIH();
}
//display the overall network error
//after each epoch
calcOverallError();
if (gmp_mod($j, 50) == 0) {
print "epoch = " . $j . " RMS Error = " . $RMSerror . "</br>";
}
}
//training has finished
//display the results
displayResults();
}
开发者ID:0-php,项目名称:AI,代码行数:34,代码来源:mlpnn.php
示例4: getCycleWeatherValue
/**
* @param int $cycle weather cycle we in (hours/3)
* @param CWeatherFunction $wf cycle season weather function (weights)
*
* @return WeatherValue
*/
public function getCycleWeatherValue($cycle, CWeatherFunction $wf)
{
$numWS = $wf->getNumWeatherSetups();
if (!$numWS) {
return 0;
}
/* old weather
$noiseValue = $this->rawWeatherProvider($cycle);
// sum all weights, usually adds up to 100
$value = (int)($noiseValue * $wf->getWeatherSetupsTotalWeight());
*/
$noiseValue = \Nel\Misc\wang_hash64($cycle);
// noise is 64bit unsigned, so use GMP library
// value = wangHash64(cycle) % wf.getWeatherSetupsTotalWeight();
$value = gmp_strval(gmp_mod($noiseValue, $wf->getWeatherSetupsTotalWeight()));
$currWeight = 0;
for ($k = 0; $k < $numWS; $k++) {
$weight = $wf->getWeatherSetupWeight($k);
if ($value >= $currWeight && $value < $currWeight + $weight) {
$scaledWeather = ($value - $currWeight) / $weight + $k;
$weather = $scaledWeather / $numWS;
return new WeatherValue($k, $weather, $wf);
}
$currWeight += $weight;
}
return new WeatherValue($numWS, 1, $wf);
}
开发者ID:nimetu,项目名称:ryzom_weather,代码行数:34,代码来源:CPredictWeather.php
示例5: GetAuthID
function GetAuthID($i64friendID)
{
$tmpfriendID = $i64friendID;
$iServer = "1";
if (extension_loaded('bcmath') == 1) {
//decode communityid with bcmath
if (bcmod($i64friendID, "2") == "0") {
$iServer = "0";
}
$tmpfriendID = bcsub($tmpfriendID, $iServer);
if (bccomp("76561197960265728", $tmpfriendID) == -1) {
$tmpfriendID = bcsub($tmpfriendID, "76561197960265728");
}
$tmpfriendID = bcdiv($tmpfriendID, "2");
return "STEAM_0:" . $iServer . ":" . $tmpfriendID;
} else {
if (extension_loaded('gmp') == 1) {
//decode communityid with gmp
if (gmp_mod($i64friendID, "2") == "0") {
$iServer = "0";
}
$tmpfriendID = gmp_sub($tmpfriendID, $iServer);
if (gmp_cmp("76561197960265728", $tmpfriendID) == -1) {
$tmpfriendID = gmp_sub($tmpfriendID, "76561197960265728");
}
$tmpfriendID = gmp_div($tmpfriendID, "2");
return "STEAM_0:" . $iServer . ":" . gmp_strval($tmpfriendID);
}
}
return false;
}
开发者ID:GoeGaming,项目名称:bans.sevenelevenclan.org,代码行数:31,代码来源:steam.inc.php
示例6: packLong
/**
* Pack a long.
*
* If it is a 32bit PHP we suppose that this log is treated by bcmath
* TODO 32bit
*
* @param int|string $value
*
* @return string the packed long
*/
public static function packLong($value)
{
if (PHP_INT_SIZE > 4) {
$value = (int) $value;
$binaryString = chr($value >> 56 & 0xff) . chr($value >> 48 & 0xff) . chr($value >> 40 & 0xff) . chr($value >> 32 & 0xff) . chr($value >> 24 & 0xff) . chr($value >> 16 & 0xff) . chr($value >> 8 & 0xff) . chr($value & 0xff);
} else {
/*
* To get the two's complement of a binary number,
* the bits are inverted, or "flipped",
* by using the bitwise NOT operation;
* the value of 1 is then added to the resulting value
*/
$bitString = '';
$isNegative = $value[0] == '-';
if (function_exists("bcmod")) {
//add 1 for the two's complement
if ($isNegative) {
$value = bcadd($value, '1');
}
while ($value !== '0') {
$bitString = (string) abs((int) bcmod($value, '2')) . $bitString;
$value = bcdiv($value, '2');
}
} elseif (function_exists("gmp_mod")) {
//add 1 for the two's complement
if ($isNegative) {
$value = gmp_strval(gmp_add($value, '1'));
}
while ($value !== '0') {
$bitString = gmp_strval(gmp_abs(gmp_mod($value, '2'))) . $bitString;
$value = gmp_strval(gmp_div_q($value, '2'));
}
} else {
while ($value != 0) {
list($value, $remainder) = self::str2bin((string) $value);
$bitString = $remainder . $bitString;
}
}
//Now do the logical not for the two's complement last phase
if ($isNegative) {
$len = strlen($bitString);
for ($x = 0; $x < $len; $x++) {
$bitString[$x] = $bitString[$x] == '1' ? '0' : '1';
}
}
//pad to have 64 bit
if ($bitString != '' && $isNegative) {
$bitString = str_pad($bitString, 64, '1', STR_PAD_LEFT);
} else {
$bitString = str_pad($bitString, 64, '0', STR_PAD_LEFT);
}
$hi = substr($bitString, 0, 32);
$lo = substr($bitString, 32, 32);
$hiBin = pack('H*', str_pad(base_convert($hi, 2, 16), 8, 0, STR_PAD_LEFT));
$loBin = pack('H*', str_pad(base_convert($lo, 2, 16), 8, 0, STR_PAD_LEFT));
$binaryString = $hiBin . $loBin;
}
return $binaryString;
}
开发者ID:emman-ok,项目名称:PhpOrient,代码行数:69,代码来源:Writer.php
示例7: irand
function irand($min, $max = null)
{
if (is_null($max)) {
$max = $min;
$min = 0;
}
$this->next();
return gmp_intval(gmp_mod(gmp_init('0x' . $this->context), gmp_init($max - $min))) + $min;
}
开发者ID:nyan-cat,项目名称:easyweb,代码行数:9,代码来源:generator.php
示例8: generate
public function generate($serial)
{
$mul = gmp_mul(strval($this->mulFactor), strval($serial));
$add = gmp_add($mul, $this->diffFactor);
$mod = gmp_mod($add, strval($this->amount));
$num = gmp_strval($mod);
// $num = ($this->mulFactor * $serial + $this->diffFactor) % $this->amount;
return str_pad($num, $this->length, $this->padding, STR_PAD_LEFT);
}
开发者ID:qiuqiux,项目名称:serialno,代码行数:9,代码来源:PseudoRandom.php
示例9: inc
public static function inc($X, $n)
{
$s = gmp_strval($X, 2);
$s1 = (string) substr($s, 0, -$n);
$s = gmp_add(gmp_init(substr($s, -$n), 2), 1);
$s = gmp_mod($s, gmp_pow(2, $n));
$s2 = str_pad(gmp_strval($s, 2), $n, '0', STR_PAD_LEFT);
return gmp_init($s1 . $s2, 2);
}
开发者ID:fpoirotte,项目名称:pssht,代码行数:9,代码来源:GCM.php
示例10: testmod
public function testmod()
{
$a = 1234;
$b = '1234123412341234123412341234123412412341234213412421341342342';
$c = '0x1234123412341234123412341234123412412341234213412421341342342';
$math = new GmpEngine();
$this->assertEquals(gmp_strval(gmp_mod($a, $a)), $math->mod($a, $a));
$this->assertEquals(gmp_strval(gmp_mod($b, $b)), $math->mod($b, $b));
$this->assertEquals(gmp_strval(gmp_mod($c, $c)), $math->mod($c, $c));
$this->assertEquals(0, $math->mod(1, 1));
}
开发者ID:bitpay,项目名称:php-client,代码行数:11,代码来源:GmpEngineTest.php
示例11: edwards
public function edwards($P, $Q)
{
$x1 = $P[0];
$y1 = $P[1];
$x2 = $Q[0];
$y2 = $Q[1];
$t = gmp_mul($this->params['d'], gmp_mul(gmp_mul($x1, $x2), gmp_mul($y1, $y2)));
$x3 = gmp_mul(gmp_add(gmp_mul($x1, $y2), gmp_mul($x2, $y1)), $this->inv(gmp_add(1, $t)));
$y3 = gmp_mul(gmp_add(gmp_mul($y1, $y2), gmp_mul($x1, $x2)), $this->inv(gmp_sub(1, $t)));
return array(gmp_mod($x3, $this->params['q']), gmp_mod($y3, $this->params['q']));
}
开发者ID:fpoirotte,项目名称:pssht,代码行数:11,代码来源:ED25519.php
示例12: nextSeed
private static function nextSeed()
{
// GMP available
if (sjMathRandom::$m_hasGMP) {
sjMathRandom::$m_seed = (int) gmp_mod(gmp_add(gmp_mul(sjMathRandom::$m_seed, sjMathRandom::PARAM_A), sjMathRandom::PARAM_B), sjMathRandom::PARAM_C);
} else {
if (sjMathRandom::$m_hasBCMath) {
sjMathRandom::$m_seed = (int) bcmod(bcadd(bcmul(sjMathRandom::$m_seed, sjMathRandom::PARAM_A), sjMathRandom::PARAM_B), sjMathRandom::PARAM_C);
} else {
die('sjMathRandom: no suported math library available');
}
}
}
开发者ID:russx2,项目名称:tap-trap,代码行数:13,代码来源:MathRandom.class.php
示例13: is_pentagonal
function is_pentagonal($num)
{
// we do a sqr with remainder
list($sr, $rem) = gmp_sqrtrem(gmp_add(gmp_mul(24, $num), 1));
// if it's not an exact root don't bother with the rest
if (gmp_strval($rem) == '0') {
$d = gmp_add($sr, 1);
$m = gmp_strval(gmp_mod($d, 6));
if ($m == '0') {
return true;
}
}
return false;
}
开发者ID:arjona,项目名称:euler,代码行数:14,代码来源:45.php
示例14: number62_encode
/**
* Назначение: Основные пользовательские функции
*/
function number62_encode($number)
{
if (preg_match('#^[0-9]+$#iu', $number) == 0) {
return "";
}
$out = "";
$string = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
do {
$key = gmp_mod($number, 62);
$out = $string[$key] . $out;
$number = gmp_strval(gmp_div_q($number, 62, GMP_ROUND_ZERO));
} while (gmp_cmp($number, 0) > 0);
return $out;
}
开发者ID:AlexanderGrom,项目名称:knee,代码行数:17,代码来源:main.php
示例15: getEncodedValue
protected function getEncodedValue()
{
$numericValue = gmp_init($this->value, 10);
$contentLength = $this->getContentLength();
if (gmp_sign($numericValue) < 0) {
$numericValue = gmp_add($numericValue, gmp_sub(gmp_pow(2, 8 * $contentLength), 1));
$numericValue = gmp_add($numericValue, 1);
}
$result = '';
for ($shiftLength = ($contentLength - 1) * 8; $shiftLength >= 0; $shiftLength -= 8) {
$octet = gmp_strval(gmp_mod($this->rightShift($numericValue, $shiftLength), 256));
$result .= chr($octet);
}
return $result;
}
开发者ID:afk11,项目名称:phpasn1,代码行数:15,代码来源:Integer.php
示例16: Zend_OpenId_bigNumToBin2
function Zend_OpenId_bigNumToBin2($bn)
{
if (extension_loaded('gmp')) {
/*The GMP conversion code in this function was liberally copied
and adapted from JanRain's Auth_OpenId_MathLibrary::longToBinary*/
$cmp = gmp_cmp($bn, 0);
if ($cmp < 0) {
throw new Zend_OpenId_Exception('Big integer arithmetic error', Zend_OpenId_Exception::ERROR_LONG_MATH);
}
if ($cmp == 0) {
return "";
}
$bytes = array();
while (gmp_cmp($bn, 0) > 0) {
array_unshift($bytes, gmp_mod($bn, 256));
$bn = gmp_div($bn, pow(2, 8));
}
if ($bytes && $bytes[0] > 127) {
array_unshift($bytes, 0);
}
$string = '';
foreach ($bytes as $byte) {
$string .= pack('C', $byte);
}
return $string;
} else {
if (extension_loaded('bcmath')) {
$cmp = bccomp($bn, 0);
if ($cmp == 0) {
return chr(0);
} else {
if ($cmp < 0) {
throw new Zend_OpenId_Exception('Big integer arithmetic error', Zend_OpenId_Exception::ERROR_LONG_MATH);
}
}
$bin = "";
while (bccomp($bn, 0) > 0) {
$bin = chr(bcmod($bn, 256)) . $bin;
$bn = bcdiv($bn, 256);
}
return $bin;
}
}
throw new Zend_OpenId_Exception('The system doesn\'t have proper big integer extension', Zend_OpenId_Exception::UNSUPPORTED_LONG_MATH);
}
开发者ID:Tony133,项目名称:zf-web,代码行数:45,代码来源:bignum_patch.php
示例17: recoverPubKey
function recoverPubKey($r, $s, $e, $recoveryFlags, $G)
{
$isYEven = ($recoveryFlags & 1) != 0;
$isSecondKey = ($recoveryFlags & 2) != 0;
$curve = $G->getCurve();
$signature = new Signature($r, $s);
// Precalculate (p + 1) / 4 where p is the field order
static $p_over_four;
// XXX just assuming only one curve/prime will be used
if (!$p_over_four) {
$p_over_four = gmp_div(gmp_add($curve->getPrime(), 1), 4);
}
// 1.1 Compute x
if (!$isSecondKey) {
$x = $r;
} else {
$x = gmp_add($r, $G->getOrder());
}
// 1.3 Convert x to point
$alpha = gmp_mod(gmp_add(gmp_add(gmp_pow($x, 3), gmp_mul($curve->getA(), $x)), $curve->getB()), $curve->getPrime());
$beta = NumberTheory::modular_exp($alpha, $p_over_four, $curve->getPrime());
// If beta is even, but y isn't or vice versa, then convert it,
// otherwise we're done and y == beta.
if (isBignumEven($beta) == $isYEven) {
$y = gmp_sub($curve->getPrime(), $beta);
} else {
$y = $beta;
}
// 1.4 Check that nR is at infinity (implicitly done in construtor)
$R = new Point($curve, $x, $y, $G->getOrder());
$point_negate = function ($p) {
return new Point($p->curve, $p->x, gmp_neg($p->y), $p->order);
};
// 1.6.1 Compute a candidate public key Q = r^-1 (sR - eG)
$rInv = NumberTheory::inverse_mod($r, $G->getOrder());
$eGNeg = $point_negate(Point::mul($e, $G));
$Q = Point::mul($rInv, Point::add(Point::mul($s, $R), $eGNeg));
// 1.6.2 Test Q as a public key
$Qk = new PublicKey($G, $Q);
if ($Qk->verifies($e, $signature)) {
return $Qk;
}
return false;
}
开发者ID:iloveyou416068,项目名称:Server-RPC-Framework,代码行数:44,代码来源:verifymessage.php
示例18: deskripsi
function deskripsi($chiper, $d, $n)
{
$time_start = microtime(true);
//Pesan Enkripsi dipecah menjadi array dengan batasan "+"
$hasildekrip = '';
$hasil = '';
$dekrip = explode(" ", $chiper);
foreach ($dekrip as $nilai) {
//Rumus Deskripsi ---> PlainTeks = <enkripsi>^<d>mod<n>
$gm1 = gmp_pow($nilai, gmp_strval($d));
$gm2 = gmp_mod($gm1, $n);
$gm3 = gmp_strval($gm2);
$hasildekrip .= chr($gm3);
}
$time_end = microtime(true);
// Waktu Eksekusi
$time = $time_end - $time_start;
$hasil = array($time, $hasildekrip);
return $hasil;
}
开发者ID:senusop,项目名称:ci,代码行数:20,代码来源:fungsiRSA.php
示例19: printmsg
function printmsg($message, $pwd)
{
$mod = gmp_init('fffffffdffffffffffffffffffffffff', 16);
$mul = gmp_init('b562a81099dff41937c5ae51ba7427a4', 16);
$key = str_repeat(sprintf('%04x', crc32($pwd) & 0xffff), 8);
$key = gmp_init($key, 16);
$pwd = gmp_init($pwd, 16);
for ($i = 0; $i < strlen($message); $i += 32) {
$msg = substr($message, $i, 32);
$msg = gmp_init($msg, 16);
$msg = gmp_add($msg, $pwd);
$msg = gmp_mul($msg, $mul);
$msg = gmp_add($msg, $key);
$msg = gmp_mod($msg, $mod);
$msg = gmp_strval($msg, 16);
$msg = str_pad($msg, 32, '0', STR_PAD_LEFT);
$msg = pack('H*', $msg);
echo $msg;
}
}
开发者ID:Retord,项目名称:write-ups-2014,代码行数:20,代码来源:message.php
示例20: _verifyByGmp
/**
* verify using gmp extendsions
*/
function _verifyByGmp($message, $sig, $sigKeys)
{
$p = $sigKeys['p'];
$q = $sigKeys['q'];
$g = $sigKeys['g'];
$pubKey = $sigKeys['pub_key'];
list($r_sig, $s_sig) = explode(":", $sig);
$r_sig = base64_decode($r_sig);
$s_sig = base64_decode($s_sig);
$p = gmp_init($p);
$q = gmp_init($q);
$g = gmp_init($g);
$pubKey = gmp_init($pubKey);
$s1 = Security_DSA::_bindecGmp($r_sig);
$s2 = Security_DSA::_bindecGmp($s_sig);
$w = gmp_invert($s2, $q);
$hash_m = gmp_init('0x' . sha1($message));
$u1 = gmp_mod(gmp_mul($hash_m, $w), $q);
$u2 = gmp_mod(gmp_mul($s1, $w), $q);
$v = gmp_mod(gmp_mod(gmp_mul(gmp_powm($g, $u1, $p), gmp_powm($pubKey, $u2, $p)), $p), $q);
return gmp_cmp($v, $s1) == 0;
}
开发者ID:orangeal2o3,项目名称:pukiwiki-plugin,代码行数:25,代码来源:DSA.php
注:本文中的gmp_mod函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论