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


PHP gmp_init函数代码示例

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


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

示例1: setValue

 public function setValue(Content $content)
 {
     $binaryData = $content->binaryData;
     $offsetIndex = 0;
     $contentLength = $this->contentLength->length;
     $isNegative = (ord($binaryData[$offsetIndex]) & 0x80) != 0x0;
     $number = gmp_init(ord($binaryData[$offsetIndex++]) & 0x7f, 10);
     for ($i = 0; $i < $contentLength - 1; $i++) {
         $number = gmp_or(gmp_mul($number, 0x100), ord($binaryData[$offsetIndex++]));
     }
     if ($isNegative) {
         $number = gmp_sub($number, gmp_pow(2, 8 * $contentLength - 1));
     }
     $value = gmp_strval($number, 10);
     if (is_string($value)) {
         // remove gaps between hex digits
         $value = preg_replace('/\\s|0x/', '', $value);
     } elseif (is_numeric($value)) {
         $value = dechex($value);
     } else {
         throw new Exception('OctetString: unrecognized input type!');
     }
     if (strlen($value) % 2 != 0) {
         // transform values like 1F2 to 01F2
         $value = '0' . $value;
     }
     $this->value = $value;
 }
开发者ID:Adapik,项目名称:PHPASN1,代码行数:28,代码来源:Integer.php

示例2: __construct

 /**
  * Constructor
  *
  * @param number $flags Flags
  * @param int $width The number of flags. If width is larger than number of
  *        bits in $flags, zeroes are prepended to flag field.
  */
 public function __construct($flags, $width)
 {
     if (!$width) {
         $this->_flags = "";
     } else {
         // calculate number of unused bits in last octet
         $last_octet_bits = $width % 8;
         $unused_bits = $last_octet_bits ? 8 - $last_octet_bits : 0;
         $num = gmp_init($flags);
         // mask bits outside bitfield width
         $mask = gmp_sub(gmp_init(1) << $width, 1);
         $num &= $mask;
         // shift towards MSB if needed
         $data = gmp_export($num << $unused_bits, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
         $octets = unpack("C*", $data);
         $bits = count($octets) * 8;
         // pad with zeroes
         while ($bits < $width) {
             array_unshift($octets, 0);
             $bits += 8;
         }
         $this->_flags = pack("C*", ...$octets);
     }
     $this->_width = $width;
 }
开发者ID:sop,项目名称:asn1,代码行数:32,代码来源:Flags.php

示例3: createDependencies

 /**
  * @before
  */
 public function createDependencies()
 {
     $this->mathInterface = new GmpMath();
     $points = ['R' => 1, 'S' => 2];
     $this->signature = new Signature(gmp_init($points['R'], 10), gmp_init($points['S'], 10));
     $this->signatureData = ['sha256' => pack('H*', str_repeat('0', 63) . $points['R'] . str_repeat('0', 63) . $points['S']), 'sha384' => pack('H*', str_repeat('0', 95) . $points['R'] . str_repeat('0', 95) . $points['S']), 'sha512' => pack('H*', str_repeat('0', 131) . $points['R'] . str_repeat('0', 131) . $points['S'])];
 }
开发者ID:lcobucci,项目名称:jwt,代码行数:10,代码来源:SignatureSerializerTest.php

示例4: testGMP

 public function testGMP()
 {
     $math = \Mdanter\Ecc\EccFactory::getAdapter();
     $I_l = "e97a4d6be13f8f5804c0a76080428fc6d51260f74801678c4127045d2640af14";
     $private_key = "142018c66b43a95de58c1cf603446fc0da322bc15fb4df068b844b57c706dd05";
     $n = "115792089237316195423570985008687907852837564279074904382605163141518161494337";
     $gmp_I_l = gmp_init($I_l, 16);
     $gmp_private_key = gmp_init($private_key, 16);
     $gmp_add = gmp_add($gmp_I_l, $gmp_private_key);
     $gmp_add_res = gmp_strval($gmp_add, 10);
     $this->assertEquals("105604983404708440304568772161069255144976878830542744455590282065741265022740", gmp_strval($gmp_I_l));
     $this->assertEquals("9102967069016248707169900673545386030247334423973996501079368232055584775429", gmp_strval($gmp_private_key));
     $this->assertEquals("114707950473724689011738672834614641175224213254516740956669650297796849798169", gmp_strval($gmp_add));
     $this->assertEquals("114707950473724689011738672834614641175224213254516740956669650297796849798169", gmp_strval(gmp_div_r($gmp_add, gmp_init($n))));
     $this->assertEquals("-4", gmp_strval(gmp_cmp(0, gmp_div_r($gmp_add, $n))));
     $this->assertEquals("230500039711040884435309657843302549028061777533591645339274813439315011292506", gmp_strval(gmp_add(gmp_init($n), gmp_div_r($gmp_add, gmp_init($n)))));
     $gmp_mod2 = $math->mod($gmp_add_res, $n);
     $this->assertTrue(is_string($gmp_mod2));
     $this->assertEquals("114707950473724689011738672834614641175224213254516740956669650297796849798169", $gmp_mod2);
     $this->assertEquals("114707950473724689011738672834614641175224213254516740956669650297796849798169", $gmp_mod2);
     // when no base is provided both a resource and string work
     $this->assertEquals("114707950473724689011738672834614641175224213254516740956669650297796849798169", gmp_strval(gmp_init($gmp_mod2)));
     $this->assertEquals("114707950473724689011738672834614641175224213254516740956669650297796849798169", gmp_strval($gmp_mod2));
     // when base is provided it fails on HHVM when inputting a string
     $this->assertEquals("fd9a66324c8338b5ea4cc4568386ff87af448cb8a7b64692ccab4fb4ed478c19", gmp_strval(gmp_init($gmp_mod2), 16));
     // $this->assertEquals("fd9a66324c8338b5ea4cc4568386ff87af448cb8a7b64692ccab4fb4ed478c19", gmp_strval($gmp_mod2, 16));
     $this->assertEquals("fd9a66324c8338b5ea4cc4568386ff87af448cb8a7b64692ccab4fb4ed478c19", str_pad(gmp_strval(gmp_init($gmp_mod2), 16), 64, '0', STR_PAD_LEFT));
 }
开发者ID:NucleusStudios,项目名称:bitcoin-lib-php,代码行数:28,代码来源:BIP32CoreTest.php

示例5: _baseConvert

 /**
  * _baseConvert
  *
  * Convert values from base-A to base-B with GMP-functions
  *
  * @param  string $value Input value for convert
  * @param  int    $from  From base-A value
  * @param  int    $to    To base-B value
  * @return string        Result string
  */
 private static function _baseConvert($value, $from, $to)
 {
     if (!function_exists('gmp_init')) {
         throw new \SystemErrorException(array('title' => 'HashHelper error', 'description' => 'Requires the PHP gmp module'));
     }
     return gmp_strval(gmp_init($value, $from), $to);
 }
开发者ID:nsedenkov,项目名称:phpsu,代码行数:17,代码来源:HashHelper.php

示例6: __construct

 /**
  * Creates a bignum.
  *
  * @param mixed $str An integer, a string in base 2 to 36, or a byte stream in base 256
  * @param int $base an integer between 2 and 36, or 256
  * @return resource a bignum
  */
 public function __construct($str, $base = 10)
 {
     switch ($base) {
         case 10:
             if (BIGNUM_GMP) {
                 $this->value = gmp_init($str, 10);
             } else {
                 $this->value = $str;
             }
             return;
             break;
         case 256:
             $bytes = array_merge(unpack('C*', $str));
             $value = (new BigNum(0))->value;
             foreach ($bytes as $byte) {
                 $value = $this->_mul($value, 256);
                 $value = $this->_add($value, (new BigNum($byte))->value);
             }
             $this->value = $value;
             return;
             break;
         default:
             if (!is_integer($base) || $base < 2 || $base > 36) {
                 return FALSE;
             }
             $value = (new BigNum(0))->value;
             for ($i = 0; $i < strlen($str); $i++) {
                 $value = $this->_mul($value, $base);
                 $value = $this->_add($value, (new BigNum(base_convert($str[$i], $base, 10)))->value);
             }
             $this->value = $value;
             return;
     }
     throw new \RuntimeException();
 }
开发者ID:J0s3f,项目名称:simpleid,代码行数:42,代码来源:BigNum.php

示例7: assetNameToIDHex

 protected function assetNameToIDHex($asset_name)
 {
     if ($asset_name == 'BTC') {
         return '0';
     }
     if ($asset_name == 'XCP') {
         return '1';
     }
     if (substr($asset_name, 0, 1) == 'A') {
         // numerical asset
         // An integer between 26^12 + 1 and 256^8 (inclusive)
         $asset_id = gmp_init(substr($asset_name, 1));
         if ($asset_id < gmp_init(26) ** 12 + 1) {
             throw new Exception("Asset ID was too low", 1);
         }
         if ($asset_id > gmp_init(2) ** 64 - 1) {
             throw new Exception("Asset ID was too high", 1);
         }
         return gmp_strval($asset_id, 16);
     }
     $n = gmp_init(0);
     for ($i = 0; $i < strlen($asset_name); $i++) {
         $n = gmp_mul($n, 26);
         $char = ord(substr($asset_name, $i, 1));
         if ($char < 65 or $char > 90) {
             throw new Exception("Asset name invalid", 1);
         }
         $digit = $char - 65;
         $n = gmp_add($n, $digit);
     }
     return gmp_strval($n, 16);
 }
开发者ID:tokenly,项目名称:counterparty-transaction-composer,代码行数:32,代码来源:OpReturnBuilder.php

示例8: import

 public function import($data, $hex = false)
 {
     if (!$hex) {
         $data = bin2hex($data);
     }
     $this->_gmp = gmp_init($data, 16);
 }
开发者ID:SandeepUmredkar,项目名称:PortalSMIP,代码行数:7,代码来源:Gmp.php

示例9: getIpAttribute

 protected function getIpAttribute($value)
 {
     if (!is_null($value)) {
         $value = inet_ntop(gmp_export(gmp_init($value)));
     }
     return $value;
 }
开发者ID:danhunsaker,项目名称:eloquent-mutant-caster,代码行数:7,代码来源:CastIP.php

示例10: BitTest

 public static function BitTest($Number, $Bit)
 {
     if (is_resource($Number) !== true) {
         $Number = gmp_init($Number);
     }
     return gmp_testbit($Number, $Bit - 1);
 }
开发者ID:davispuh,项目名称:php-utils,代码行数:7,代码来源:Utilities.php

示例11: __construct

 /**
  * This class accepts two parameters on construction. Only the
  * first ($number) is required.
  *
  * @param $number string
  * @param $base int
  */
 public function __construct($number, $base = 10)
 {
     $this->reference = $number;
     $this->base = intval($base);
     $this->int_max = gmp_init(PHP_INT_MAX, $this->base);
     $this->number = gmp_init($number, $this->base);
 }
开发者ID:drmyersii,项目名称:numbers,代码行数:14,代码来源:NumberW.php

示例12: make

 /**
  * @return GmpBigInteger
  **/
 public static function make($number, $base = 10)
 {
     Assert::isTrue(is_numeric($number));
     $result = new self();
     $result->resource = gmp_init($number, $base);
     return $result;
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:10,代码来源:GmpBigInteger.class.php

示例13: testInvalidCipher

 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage Unknown cipher method
  */
 public function testInvalidCipher()
 {
     $privateKey = CurveFactory::getGeneratorByName('nistp256')->getPrivateKeyFrom(gmp_init(100));
     $iv = random_bytes(16);
     $method = 'not-a-known-cipher';
     new EncryptedPrivateKey($privateKey, $method, $iv);
 }
开发者ID:afk11,项目名称:ecssh,代码行数:11,代码来源:EncryptedPrivateKeyTest.php

示例14: pidigits

function pidigits($N)
{
    $k = 1;
    $n1 = gmp_init(4);
    $n2 = gmp_init(3);
    $d = gmp_init(1);
    $i = 0;
    while ($i < $N) {
        $y = digit($n1, $n2, $d);
        if ($y !== false) {
            echo gmp_strval($y);
            $i++;
            if ($i % 10 == 0) {
                echo "\t:", $i, "\n";
            }
            extractd($n1, $n2, $d, $y);
        } else {
            produce($n1, $n2, $d, $k);
            $k++;
        }
    }
    if ($i % 10 != 0) {
        echo str_repeat(' ', 10 - $N % 10), "\t:", $N, "\n";
    }
}
开发者ID:neoedmund,项目名称:benchmarksgame,代码行数:25,代码来源:pidigits.php-3.php

示例15: generate

 public static function generate($ver = 4, $node = null, $clockSeq = null, $ns = null, $name = null)
 {
     $uuid = null;
     /* Create a new UUID based on provided data. */
     switch ((int) $ver) {
         case 1:
             $uuid = Uuid::uuid1($node, $clockSeq);
             break;
         case 2:
             // Version 2 is not supported
             throw new \RuntimeException('UUID version 2 is unsupported.');
         case 3:
             $uuid = Uuid::uuid3($ns, $name);
             break;
         case 4:
             $uuid = Uuid::uuid4();
             break;
         case 5:
             $uuid = Uuid::uuid5($ns, $name);
             break;
         default:
             throw new \RuntimeException('Selected UUID version is invalid or unsupported.');
     }
     if (function_exists('gmp_strval')) {
         return gmp_strval(gmp_init($uuid->getHex(), 16), 62);
     }
     return Base62::encode((string) $uuid->getInteger());
 }
开发者ID:gponster,项目名称:laravel-url62-uuid,代码行数:28,代码来源:Url62UuidGenerator.php


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