本文整理汇总了PHP中gmp_and函数的典型用法代码示例。如果您正苦于以下问题:PHP gmp_and函数的具体用法?PHP gmp_and怎么用?PHP gmp_and使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gmp_and函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: comparebit
function comparebit($key, $value)
{
if (isset($this->_bitmap[$key1])) {
if (gmp_and($this->_bitmap[$key1], $value)) {
return true;
}
}
return false;
}
示例2: encodeSFixed64
/**
* {@inheritdoc}
*/
public function encodeSFixed64($sFixed64)
{
$value = $this->is32Bit ? gmp_and($sFixed64, '0x0ffffffffffffffff') : gmp_init(sprintf('%u', $sFixed64));
$bytes = '';
for ($i = 0; $i < 8; ++$i) {
$bytes .= chr(gmp_intval(gmp_and($value, $this->gmp_xff)));
$value = gmp_div_q($value, $this->gmp_x100);
}
return $bytes;
}
示例3: testPutTAGLong
/**
* @dataProvider providerTestTAGLong
*/
public function testPutTAGLong($value)
{
$fPtr = fopen($this->vFile->url(), 'wb');
// 32-bit longs seem to be too long for pack() on 32-bit machines. Split into 4x16-bit instead.
$quarters[0] = gmp_div(gmp_and($value, '0xFFFF000000000000'), gmp_pow(2, 48));
$quarters[1] = gmp_div(gmp_and($value, '0x0000FFFF00000000'), gmp_pow(2, 32));
$quarters[2] = gmp_div(gmp_and($value, '0x00000000FFFF0000'), gmp_pow(2, 16));
$quarters[3] = gmp_and($value, '0xFFFF');
$binary = pack('nnnn', gmp_intval($quarters[0]), gmp_intval($quarters[1]), gmp_intval($quarters[2]), gmp_intval($quarters[3]));
$this->dataHandler->putTAGLong($fPtr, $value);
$this->assertSame($binary, $this->vFile->getContent());
}
示例4: getMask
/**
* Return netmask
*
* @return IPv6
*/
public function getMask()
{
if ($this->mask === null) {
if ($this->prefix == 0) {
$this->mask = new $this->ip_class(0);
} else {
$max_int = gmp_init(constant("{$this->ip_class}::MAX_INT"));
$mask = gmp_shiftl($max_int, constant("{$this->ip_class}::NB_BITS") - $this->prefix);
$mask = gmp_and($mask, $max_int);
// truncate to 128 bits only
$this->mask = new $this->ip_class($mask);
}
}
return $this->mask;
}
示例5: decode
/**
* @param string $octets
*
* @throws InvalidArgumentException if the given octets represent a malformed base-128 value or the decoded value would exceed the the maximum integer length
*
* @return int
*/
public static function decode($octets)
{
$bitsPerOctet = 7;
$value = gmp_init(0, 10);
$i = 0;
$leftShift = function ($number, $positions) {
return gmp_mul($number, gmp_pow(2, $positions));
};
while (true) {
if (!isset($octets[$i])) {
throw new InvalidArgumentException(sprintf('Malformed base-128 encoded value (0x%s).', strtoupper(bin2hex($octets)) ?: '0'));
}
$octet = gmp_init(ord($octets[$i++]), 10);
$l1 = $leftShift($value, $bitsPerOctet);
$r1 = gmp_and($octet, 0x7f);
$value = gmp_add($l1, $r1);
if (0 === gmp_cmp(gmp_and($octet, 0x80), 0)) {
break;
}
}
return gmp_strval($value);
}
示例6: 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);
}
示例7: bit_and
/**
* Bitwise AND
*
* @param $value mixed anything that can be converted into an IP object
* @return IP
*/
public function bit_and($value)
{
if (!$value instanceof self) {
$value = new $this->class($value);
}
return new $this->class(gmp_and($this->ip, $value->ip));
}
示例8: decrypt
private function decrypt($encrypted_password)
{
$encrypted_password = trim($encrypted_password);
if (!strlen($encrypted_password)) {
return '';
}
$decoded_password = hextostr($encrypted_password);
$decrypted_password = '';
$seed = 0x2a9a;
for ($i = 0; $i < strlen($decoded_password); $i++) {
$decrypted_password .= chr(ord($decoded_password[$i]) ^ $seed >> 8 & 0xff);
$seed += ord($decoded_password[$i]);
$seed = hexdec(gmp_strval(gmp_and(gmp_add(gmp_mul("{$seed}", "0x8141"), "0x3171"), "0xffff"), 16));
}
return $decrypted_password;
}
示例9: 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);
}
示例10: mul
public static function mul($x2, Point $p1)
{
$e = $x2;
if (self::cmp($p1, self::INFINITY) == 0) {
return self::INFINITY;
}
if ($p1->order != null) {
$e = gmp_mod($e, $p1->order);
}
if (gmp_cmp($e, 0) == 0) {
return self::INFINITY;
}
if (gmp_cmp($e, 0) > 0) {
$e3 = gmp_mul(3, $e);
$negative_self = new Point($p1->curve, $p1->x, gmp_neg($p1->y), $p1->order);
$i = gmp_div(self::leftmost_bit($e3), 2);
$result = $p1;
while (gmp_cmp($i, 1) > 0) {
$result = self::double($result);
if (gmp_cmp(gmp_and($e3, $i), 0) != 0 && gmp_cmp(gmp_and($e, $i), 0) == 0) {
$result = self::add($result, $p1);
}
if (gmp_cmp(gmp_and($e3, $i), 0) == 0 && gmp_cmp(gmp_and($e, $i), 0) != 0) {
$result = self::add($result, $negative_self);
}
$i = gmp_div($i, 2);
}
return $result;
}
}
示例11: sFixed64_gmp
public function sFixed64_gmp($value)
{
static $xff, $x100;
if (NULL === $xff) {
$xff = gmp_init(0xff);
$x100 = gmp_init(0x100);
}
$value = PHP_INT_SIZE < 8 ? gmp_and($value, '0x0ffffffffffffffff') : gmp_init(sprintf('%u', $value));
$bytes = '';
for ($i = 0; $i < 8; $i++) {
$bytes .= chr(gmp_intval(gmp_and($value, $xff)));
$value = gmp_div_q($value, $x100);
}
$this->write($bytes);
}
示例12: _normalize
/**
* Normalize
*
* Deletes leading zeros and truncates (if necessary) to maintain the appropriate precision
*
* @return Math_BigInteger
* @access private
*/
function _normalize($result)
{
$result->precision = $this->precision;
$result->bitmask = $this->bitmask;
switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP:
if (!empty($result->bitmask->value)) {
$result->value = gmp_and($result->value, $result->bitmask->value);
}
return $result;
case MATH_BIGINTEGER_MODE_BCMATH:
if (!empty($result->bitmask->value)) {
$result->value = bcmod($result->value, $result->bitmask->value);
}
return $result;
}
if (!count($result->value)) {
return $result;
}
for ($i = count($result->value) - 1; $i >= 0; $i--) {
if ($result->value[$i]) {
break;
}
unset($result->value[$i]);
}
if (!empty($result->bitmask->value)) {
$length = min(count($result->value), count($this->bitmask->value));
$result->value = array_slice($result->value, 0, $length);
for ($i = 0; $i < $length; $i++) {
$result->value[$i] = $result->value[$i] & $this->bitmask->value[$i];
}
}
return $result;
}
示例13: myrand
function myrand($max, &$seed)
{
$seed = hexdec(gmp_strval(gmp_and(gmp_add(gmp_mul("{$seed}", "0x8088405"), "1"), "0xffffffff"), 16));
$v = hexdec(gmp_strval(gmp_and(gmp_shiftr(gmp_mul("0x" . dechex($seed), "{$max}"), "32"), "0xffffffff"), 16));
return $v;
}
示例14: sign
public function sign($message)
{
$curve = \fpoirotte\Pssht\ED25519::getInstance();
$h = hash('sha512', $this->sk, true);
$a = gmp_add(gmp_pow(2, 256 - 2), gmp_and(gmp_init(bin2hex(strrev($h)), 16), gmp_sub(gmp_pow(2, 254), 8)));
$r = static::Hint(substr($h, 32) . $message);
$R = $curve->scalarmult($curve->B, $r);
$t = static::encodepoint($R) . $this->pk . $message;
$S = gmp_mod(gmp_add($r, gmp_mul(static::Hint($t), $a)), $curve->l);
return static::encodepoint($R) . static::encodeint($S);
}
示例15: Set
/**
* @param int $BitOffset
* @param int $ValueMask
* @param int $Value
*
* @return void
*/
private function Set($BitOffset, $ValueMask, $Value)
{
$this->Data = gmp_or(gmp_and($this->Data, gmp_com(self::ShiftLeft($ValueMask, $BitOffset))), self::ShiftLeft(gmp_and($Value, $ValueMask), $BitOffset));
}