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


PHP gmp_xor函数代码示例

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


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

示例1: wang_hash64

/**
 * Calculate Wang hash for 64bit unsigned integer using GMP library
 * PHP only supports signed integers even with 64bit version
 *
 * See <code/nel/include/nel/misc/wang_hash.h> on https://bitbucket.org/ryzom/ryzomcore
 *
 * @param string $key
 *
 * @return string hash
 */
function wang_hash64($key)
{
    // force $key to be base 10
    $key = gmp_init($key, 10);
    //$key = (~$key) + ($key << 21);
    $key = gmp_add(gmp_com($key), gmp_mul($key, 1 << 21));
    //$key = $key ^ ($key >> 24);
    $key = gmp_xor($key, gmp_div($key, 1 << 24));
    //$key = $key * 265;
    $key = gmp_mul($key, 265);
    //$key = $key ^ ($key >> 14);
    $key = gmp_xor($key, gmp_div($key, 1 << 14));
    //$key = $key * 21;
    $key = gmp_mul($key, 21);
    //$key = $key ^ ($key >> 28);
    $key = gmp_xor($key, gmp_div($key, 1 << 28));
    //$key = $key + ($key << 31);
    $key = gmp_add($key, gmp_mul($key, gmp_pow(2, 31)));
    // limit to 64bit
    $key = gmp_and($key, "0xFFFFFFFFFFFFFFFF");
    return gmp_strval($key, 10);
}
开发者ID:nimetu,项目名称:ryzom_weather,代码行数:32,代码来源:wang_hash.php

示例2: 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 $this->_normalize($temp);
         case MATH_BIGINTEGER_MODE_BCMATH:
             $left = $this->toBytes();
             $right = $x->toBytes();
             $length = max(strlen($left), strlen($right));
             $left = str_pad($left, $length, chr(0), STR_PAD_LEFT);
             $right = str_pad($right, $length, chr(0), STR_PAD_LEFT);
             return $this->_normalize(new Math_BigInteger($left ^ $right, 256));
     }
     $length = max(count($this->value), count($x->value));
     $result = $this->copy();
     $result->value = array_pad($result->value, $length, 0);
     $x->value = array_pad($x->value, $length, 0);
     for ($i = 0; $i < $length; ++$i) {
         $result->value[$i] ^= $x->value[$i];
     }
     return $this->_normalize($result);
 }
开发者ID:selectSIFISO,项目名称:.comsite,代码行数:32,代码来源:BigInteger.php

示例3: 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

示例4: tea_decrypt

 function tea_decrypt(&$v0, &$v1, $key)
 {
     $sum = "0xC6EF3720";
     $delta = "0x9e3779b9";
     for ($i = 0; $i < 32; $i++) {
         $v1 = hexdec(gmp_strval(gmp_and(gmp_sub("{$v1}", gmp_xor(gmp_add(gmp_shiftl("{$v0}", 4), $key[2]), gmp_xor(gmp_add("{$v0}", "{$sum}"), gmp_add(gmp_shiftr('0x' . dechex($v0), 5), $key[3])))), '0xffffffff'), 16));
         $v0 = hexdec(gmp_strval(gmp_and(gmp_sub("{$v0}", gmp_xor(gmp_add(gmp_shiftl("{$v1}", 4), $key[0]), gmp_xor(gmp_add("{$v1}", "{$sum}"), gmp_add(gmp_shiftr('0x' . dechex($v1), 5), $key[1])))), '0xffffffff'), 16));
         $sum = hexdec(gmp_strval(gmp_and(gmp_sub("{$sum}", "{$delta}"), '0xffffffff'), 16));
     }
 }
开发者ID:sh1nu11bi,项目名称:PonyBotnet_panel,代码行数:10,代码来源:password_modules.php

示例5: toggle

 /**
  * @param $value
  * @param $mask
  *
  * @return string
  */
 public static function toggle($value, $mask)
 {
     return gmp_strval(gmp_xor($value, $mask));
 }
开发者ID:packaged,项目名称:helpers,代码行数:10,代码来源:BitWiseGmp.php

示例6: list

list($sqrt2, $sqrt2rem) = gmp_sqrtrem("7");
list($sqrt3, $sqrt3rem) = gmp_sqrtrem("1048576");
echo gmp_strval($sqrt1) . ", " . gmp_strval($sqrt1rem) . "\n";
echo gmp_strval($sqrt2) . ", " . gmp_strval($sqrt2rem) . "\n";
echo gmp_strval($sqrt3) . ", " . gmp_strval($sqrt3rem) . "\n";
// gmp_strval
$a = gmp_init("0x41682179fbf5");
printf("Decimal: %s, 36-based: %s" . PHP_EOL, gmp_strval($a), gmp_strval($a, 36));
// gmp_sub
$sub = gmp_sub("281474976710656", "4294967296");
// 2^48 - 2^32
echo gmp_strval($sub) . "\n";
// gmp_testbit
$n = gmp_init("1000000");
var_dump(gmp_testbit($n, 1));
gmp_setbit($n, 1);
var_dump(gmp_testbit($n, 1));
// gmp_xor
$xor1 = gmp_init("1101101110011101", 2);
$xor2 = gmp_init("0110011001011001", 2);
$xor3 = gmp_xor($xor1, $xor2);
echo gmp_strval($xor3, 2) . "\n";
// misc
$someBigNumber = '521384146951941511609433057270365759591953092186117381932611' . '7931051185480744623799627495673518857527248912279381830119491298336733624' . '4065664308602139494639522473719070217986094370277293176752384674818467669' . '4051320005681271452635608277857713427577896091736371787214684409012654958' . '5371050792279689258923542019956112129021960864034418159813629774771309960' . '5187072113497804995105973173281609631859502445945534690830264252230825334' . '4685035261931188171010003137835332083814206171776691473035982534904287554' . '687311595628638823537875937519577818577805321712';
$a = gmp_init($someBigNumber, 10);
var_dump(gmp_strval($a) == $someBigNumber);
var_dump(gmp_strval($a, 32));
$b = gmp_init(0xffffff, 16);
var_dump(gmp_strval($b));
$c = gmp_init($b);
var_dump(gmp_strval($c, 16));
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:mostInOne.php

示例7: _binaryXor

 /**
  * Binary xor helper.
  *
  * @param string $left
  * @param string $round
  *
  * @return string Binary string.
  */
 private function _binaryXor($left, $round)
 {
     $xOr = gmp_xor(gmp_init($left, 2), gmp_init($round, 2));
     $bin = gmp_strval($xOr, 2);
     return str_pad($bin, $this->sideSize, '0', STR_PAD_LEFT);
 }
开发者ID:loostro,项目名称:cryptomute,代码行数:14,代码来源:Cryptomute.php

示例8: bitXor

 /**
  * Bitwise "xor" (^)
  *
  * @param mixed $number
  * @access public
  * @return self
  */
 public function bitXor($number)
 {
     $result = gmp_xor($this->getRawValue(), static::upgradeParam($number)->getRawValue());
     return static::factory($result);
 }
开发者ID:lamannapov,项目名称:mathematician,代码行数:12,代码来源:Gmp.php

示例9: var_dump

<?php

var_dump(gmp_strval(gmp_xor("111111", "2222222")));
var_dump(gmp_strval(gmp_xor(123123, 435234)));
var_dump(gmp_strval(gmp_xor(555, "2342341123")));
var_dump(gmp_strval(gmp_xor(-1, 3333)));
var_dump(gmp_strval(gmp_xor(4545, -20)));
var_dump(gmp_strval(gmp_xor("test", "no test")));
$n = gmp_init("987657876543456");
var_dump(gmp_strval(gmp_xor($n, "34332")));
$n1 = gmp_init("987657878765436543456");
var_dump(gmp_strval(gmp_xor($n, $n1)));
var_dump(gmp_xor($n, $n1, 1));
var_dump(gmp_xor(1));
var_dump(gmp_xor(array(), 1));
var_dump(gmp_xor(1, array()));
var_dump(gmp_xor(array(), array()));
echo "Done\n";
开发者ID:badlamer,项目名称:hhvm,代码行数:18,代码来源:gmp_xor.php

示例10: bitwiseXOR

 /**
  * Logical Exclusive-Or
  * Implemented per a request by Lluis Pamies i Juarez <lluis _a_ pamies.cat>
  *
  * @param BigInteger $x
  * @access public
  * @return BigInteger
  */
 function bitwiseXOR($x)
 {
     switch (BigInteger_MODE) {
         case BigInteger_MODE_GMP:
             $temp = new BigInteger();
             $temp->value = gmp_xor($this->value, $x->value);
             return $this->_normalize($temp);
         case BigInteger_MODE_BCMATH:
             $left = $this->toBytes();
             $right = $x->toBytes();
             $length = max(strlen($left), strlen($right));
             $left = str_pad($left, $length, chr(0), STR_PAD_LEFT);
             $right = str_pad($right, $length, chr(0), STR_PAD_LEFT);
             return $this->_normalize(new BigInteger($left ^ $right, 256));
     }
     $length = max(count($this->value), count($x->value));
     $result = $this->copy();
     if (!is_array($result->value)) {
         $result->value = [];
     }
     $result->value = array_pad($result->value, 0, $length);
     if (!is_array($x->value)) {
         $x->value = [];
     }
     $x->value = array_pad($x->value, 0, $length);
     for ($i = 0; $i < $length; ++$i) {
         $result->value[$i] = $this->value[$i] ^ $x->value[$i];
     }
     return $this->_normalize($result);
 }
开发者ID:brennantom,项目名称:hackazon,代码行数:38,代码来源:BigInteger.php

示例11: decode_long_from_array

 /**
  * @param int[] $bytes array of ascii codes of bytes to decode
  * @return string represenation of decoded long.
  */
 static function decode_long_from_array($bytes)
 {
     $b = array_shift($bytes);
     $g = gmp_init($b & 0x7f);
     $shift = 7;
     while (0 != ($b & 0x80)) {
         $b = array_shift($bytes);
         $g = gmp_or($g, self::shift_left($b & 0x7f, $shift));
         $shift += 7;
     }
     $val = gmp_xor(self::shift_right($g, 1), gmp_neg(gmp_and($g, 1)));
     return gmp_strval($val);
 }
开发者ID:wikimedia,项目名称:avro,代码行数:17,代码来源:gmp.php

示例12: bitwiseXor

 /**
  * {@inheritDoc}
  * @see \Mdanter\Ecc\MathAdapter::bitwiseXor()
  */
 public function bitwiseXor($first, $other)
 {
     return gmp_strval(gmp_xor(gmp_init($first, 10), gmp_init($other, 10)));
 }
开发者ID:sbwdlihao,项目名称:phpecc,代码行数:8,代码来源:Gmp.php

示例13: gctr

 protected function gctr($ICB, $X)
 {
     if ($X === '') {
         return '';
     }
     $Xn = str_split($X, 16);
     $n = count($Xn);
     $CB = array(1 => $ICB);
     $Yn = array();
     for ($i = 1; $i < $n; $i++) {
         $CB[$i + 1] = static::inc($CB[$i], 32);
         $t = mcrypt_generic($this->cipher, pack('H*', str_pad(gmp_strval($CB[$i], 16), 32, '0', STR_PAD_LEFT)));
         $t = gmp_xor(gmp_init(bin2hex($Xn[$i - 1]), 16), gmp_init(bin2hex($t), 16));
         $Yn[$i] = pack('H*', str_pad(gmp_strval($t, 16), 32, '0', STR_PAD_LEFT));
     }
     // Cipher
     $t = mcrypt_generic($this->cipher, pack('H*', str_pad(gmp_strval($CB[$n], 16), 32, '0', STR_PAD_LEFT)));
     // MSB Xn*
     $t = str_pad(gmp_strval(gmp_init(bin2hex($t), 16), 16), 32, '0', STR_PAD_LEFT);
     $nn = strlen($Xn[$n - 1]) << 1;
     $t = substr($t, 0, $nn);
     // Yn*
     $t = gmp_xor(gmp_init(bin2hex($Xn[$n - 1]), 16), gmp_init($t, 16));
     $Yn[$n] = pack('H*', str_pad(gmp_strval($t, 16), $nn, '0', STR_PAD_LEFT));
     return implode('', $Yn);
 }
开发者ID:fpoirotte,项目名称:pssht,代码行数:26,代码来源:GCM.php


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