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


PHP gmp_sub函数代码示例

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


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

示例1: to32Bit

 /**
  * Conver 64-bit SteamID to 32-bit SteamID
  *
  * @param string|int $userId
  *
  * @return string
  * @throws Exception
  */
 public static function to32Bit($userId)
 {
     if (!function_exists('gmp_add')) {
         throw new Exception("GMP Library not installed. Cannot convert SteamIDs.");
     }
     return gmp_strval(gmp_sub($userId, gmp_mul(bindec(self::STEAM_ID_UPPER_BITS), "4294967296")));
 }
开发者ID:sjaakmoes,项目名称:dotapi2,代码行数:15,代码来源:UserId.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: 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

示例4: sumT

function sumT($n)
{
    if (gmp_intval($n) == 1) {
        return gmp_init(1);
    }
    return gmp_add(gmp_sub(gmp_pow($n, 2), gmp_pow(gmp_init(gmp_intval($n) - 1), 2)), sumT(gmp_init(gmp_intval($n) - 1)));
    //return gmp_mod(gmp_add(gmp_sub(gmp_mod(gmp_pow($n, 2), '1000000007'), gmp_mod(gmp_pow(gmp_init(gmp_intval($n)-1), 2), '1000000007')), sumT(gmp_init(gmp_intval($n)-1))), '1000000007');
}
开发者ID:baotroy,项目名称:chal,代码行数:8,代码来源:index.php

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

示例6: getDelta

 /**
  * Return delta to last IP address
  *
  * @return IPv6
  */
 public function getDelta()
 {
     if ($this->delta === null) {
         if ($this->prefix == 0) {
             $this->delta = new $this->ip_class(constant("{$this->ip_class}::MAX_INT"));
         } else {
             $this->delta = new $this->ip_class(gmp_sub(gmp_shiftl(1, constant("{$this->ip_class}::NB_BITS") - $this->prefix), 1));
         }
     }
     return $this->delta;
 }
开发者ID:aniblaze,项目名称:php-ip,代码行数:16,代码来源:IPBlock.php

示例7: computeBaseNDigits

 private function computeBaseNDigits($number, $targetBase)
 {
     $digits = array();
     $length = $this->computeBaseNLength($number, $targetBase);
     for ($i = 0; $i < $length; $i++) {
         $pow = gmp_pow($targetBase, $length - $i - 1);
         $div = gmp_div($number, $pow, GMP_ROUND_ZERO);
         $number = gmp_sub($number, gmp_mul($div, $pow));
         $digits[] = $div;
     }
     return array_map('gmp_strval', $digits);
 }
开发者ID:thunderer,项目名称:numbase,代码行数:12,代码来源:GmpConverter.php

示例8: verifies

 public function verifies($hash, Signature $signature)
 {
     if (extension_loaded('gmp') && USE_EXT == 'GMP') {
         $G = $this->generator;
         $n = $this->generator->getOrder();
         $point = $this->point;
         $r = $signature->getR();
         $s = $signature->getS();
         if (gmp_cmp($r, 1) < 0 || gmp_cmp($r, gmp_sub($n, 1)) > 0) {
             return false;
         }
         if (gmp_cmp($s, 1) < 0 || gmp_cmp($s, gmp_sub($n, 1)) > 0) {
             return false;
         }
         $c = NumberTheory::inverse_mod($s, $n);
         $u1 = gmp_Utils::gmp_mod2(gmp_mul($hash, $c), $n);
         $u2 = gmp_Utils::gmp_mod2(gmp_mul($r, $c), $n);
         $xy = Point::add(Point::mul($u1, $G), Point::mul($u2, $point));
         $v = gmp_Utils::gmp_mod2($xy->getX(), $n);
         if (gmp_cmp($v, $r) == 0) {
             return true;
         } else {
             return false;
         }
     } else {
         if (extension_loaded('bcmath') && USE_EXT == 'BCMATH') {
             $G = $this->generator;
             $n = $this->generator->getOrder();
             $point = $this->point;
             $r = $signature->getR();
             $s = $signature->getS();
             if (bccomp($r, 1) == -1 || bccomp($r, bcsub($n, 1)) == 1) {
                 return false;
             }
             if (bccomp($s, 1) == -1 || bccomp($s, bcsub($n, 1)) == 1) {
                 return false;
             }
             $c = NumberTheory::inverse_mod($s, $n);
             $u1 = bcmod(bcmul($hash, $c), $n);
             $u2 = bcmod(bcmul($r, $c), $n);
             $xy = Point::add(Point::mul($u1, $G), Point::mul($u2, $point));
             $v = bcmod($xy->getX(), $n);
             if (bccomp($v, $r) == 0) {
                 return true;
             } else {
                 return false;
             }
         } else {
             throw new ErrorException("Please install BCMATH or GMP");
         }
     }
 }
开发者ID:AliceWonderMiscreations,项目名称:ColdAddress,代码行数:52,代码来源:PublicKey.php

示例9: kirim_chat

 public function kirim_chat()
 {
     $this->load->view("fungsiRSA");
     /* 
     		-- keterangan Masing Masing Fungsi yang dipake dari Library gmp --
     gmp_div_qr = Bagi;
     		gmp_add    = Tambah;
     		gmp_mul    = Kali;
     		gmp_sub    = Kurang;
     		gmp_gcd    = Menghitung Nilai phi;
     		gmp_strval = Convert Nomer ke String;
     */
     // Inisialisasi P = 113 & Q = 157 (Masing Masing adalah Bilangan Prima) <--- Lebih Besar Lebih Bagus
     // Menghitung N = P*Q
     $n = gmp_mul(113, 157);
     $valn = gmp_strval($n);
     // Menghitung Nilai M =(p-1)*(q-1)
     $m = gmp_mul(gmp_sub(113, 1), gmp_sub(157, 1));
     // Mencari E (Kunci Public --> (e,n))
     // Inisialisasi E = 5
     // Membuktikan E = FPB (Faktor Persekutuan Terbesar) dari E dan M = 1
     for ($e = 5; $e < 1000; $e++) {
         // Mencoba dengan Perulangan 1000 Kali
         $fpb = gmp_gcd($e, $m);
         if (gmp_strval($fpb) == '1') {
             // Jika Benar E adalah FPB dari E dan M = 1 <-- Hentikan Proses
             break;
         }
     }
     // Menghitung D (Kunci Private --> (d,n))
     // D = (($m * $i) + 1) / e = $key[1] <-- Perulangan Do While
     $i = 1;
     do {
         $key = gmp_div_qr(gmp_add(gmp_mul($m, $i), 1), $e);
         $i++;
         if ($i == 1000) {
             // Dengan Perulangan 1000 Kali
             break;
         }
     } while (gmp_strval($key[1]) != '0');
     // Hasil D = $key[0]
     $d = $key[0];
     $vald = gmp_strval($d);
     $user = $this->input->post("user");
     $pesan = $this->input->post("pesan");
     $userid = $this->input->post("iduser");
     $hasilenkripsi = enkripsi($pesan, $n, $e);
     $insert = "insert into chat (user,pesan,id_user) VALUES ('{$user}','{$hasilenkripsi}','{$userid}')";
     $this->db->query($insert);
     redirect("home/ambil_pesan");
 }
开发者ID:senusop,项目名称:myRepo,代码行数:51,代码来源:home.php

示例10: contains

 public function contains($x, $y)
 {
     $eq_zero = null;
     if (extension_loaded('gmp') && USE_EXT == 'GMP') {
         $eq_zero = gmp_cmp(gmp_Utils::gmp_mod2(gmp_sub(gmp_pow($y, 2), gmp_add(gmp_add(gmp_pow($x, 3), gmp_mul($this->a, $x)), $this->b)), $this->prime), 0);
         if ($eq_zero == 0) {
             return true;
         } else {
             return false;
         }
     } else {
         throw new ErrorException("Please install GMP");
     }
 }
开发者ID:blade-runner,项目名称:rutokenweb_php,代码行数:14,代码来源:CurveFp.php

示例11: sub

 public static function sub($x, $y)
 {
     switch (self::getMode()) {
         case self::modeGmp:
             return gmp_strval(gmp_sub($x, $y));
             break;
         case self::modeBcmath:
             return bcsub($x, $y);
             break;
         case self::modeNative:
             return $x - $y;
             break;
     }
 }
开发者ID:alexqwert,项目名称:kanon,代码行数:14,代码来源:yMath.php

示例12: GOST_verifies

 public function GOST_verifies($hash, Signature $signature)
 {
     if (extension_loaded('gmp') && USE_EXT == 'GMP') {
         $G = $this->generator;
         //P
         $n = $this->generator->getOrder();
         //q
         $point = $this->point;
         //Q
         $r = $signature->getR();
         $s = $signature->getS();
         if (gmp_cmp($r, 1) < 0 || gmp_cmp($r, gmp_sub($n, 1)) > 0) {
             return false;
         }
         if (gmp_cmp($s, 1) < 0 || gmp_cmp($s, gmp_sub($n, 1)) > 0) {
             return false;
         }
         //step 3 GOST
         $e = gmp_Utils::gmp_mod2($hash, $n);
         if (gmp_cmp($e, '0') === 0) {
             $e = gmp_init('1');
         }
         // step 4 GOST
         $v = gmp_strval(gmp_invert($e, $n));
         // step 5 GOST
         $z1 = gmp_Utils::gmp_mod2(gmp_mul($s, $v), $n);
         $z2 = gmp_Utils::gmp_mod2(gmp_mul(gmp_neg($r), $v), $n);
         // step 6 GOST
         $C = Point::add(Point::mul($z1, $G), Point::mul($z2, $point));
         $R = gmp_Utils::gmp_mod2($C->getX(), $n);
         if (0) {
             echo "n - " . $n . "\n";
             echo "h - " . $hash . "\n";
             echo "e - " . gmp_Utils::gmp_dechex($e) . "\n";
             echo "v - " . gmp_Utils::gmp_dechex($v) . "\n";
             echo "r - " . $r . "\n";
             echo "s - " . $s . "\n";
             echo "z1 - " . gmp_Utils::gmp_dechex($z1) . "\nz2 - " . gmp_Utils::gmp_dechex($z2) . "\n";
             echo "Q - " . $point . "\nG - " . $G . "\n";
             echo "C - " . $C . "\nR - " . $R . "\n";
         }
         if (gmp_cmp($R, $r) == 0) {
             return true;
         } else {
             return false;
         }
     } else {
         throw new ErrorException("Please install GMP");
     }
 }
开发者ID:blade-runner,项目名称:rutokenweb_php,代码行数:50,代码来源:PublicKey.php

示例13: __construct

 public function __construct(\Cachet\Cache $cache, \Cachet\Locker $locker)
 {
     $this->locker = $locker;
     $this->cache = $cache;
     if (extension_loaded('bcmath')) {
         $this->addCallback = 'bcadd';
         $this->subCallback = 'bcsub';
     } elseif (extension_loaded('gmp')) {
         $this->addCallback = function ($a, $b) {
             return gmp_strval(gmp_add($a, $b));
         };
         $this->subCallback = function ($a, $b) {
             return gmp_strval(gmp_sub($a, $b));
         };
     } else {
         throw new \RuntimeException("Neither bcmath nor gmp extensions present");
     }
 }
开发者ID:shabbyrobe,项目名称:cachet,代码行数:18,代码来源:SafeCache.php

示例14: testSingleBit

 /**
  * @large
  */
 public function testSingleBit()
 {
     $this->assertTrue(BitWiseGmp::isSingleBit(1));
     $this->assertTrue(BitWiseGmp::isSingleBit("1"));
     $this->assertTrue(BitWiseGmp::isSingleBit(2));
     $this->assertTrue(BitWiseGmp::isSingleBit("2"));
     $this->assertTrue(BitWiseGmp::isSingleBit(4));
     $fails = [3, 5, 6, 7, 9, 10, 11, 13, 14, 15];
     foreach ($fails as $checkBit) {
         $this->assertFalse(BitWiseGmp::isSingleBit($checkBit));
     }
     $checkBit = 4;
     for ($i = 0; $i < 10000; $i++) {
         $checkBit = gmp_mul($checkBit, 2);
         $this->assertTrue(BitWiseGmp::isSingleBit($checkBit));
         $this->assertFalse(BitWiseGmp::isSingleBit(gmp_sub($checkBit, 3)));
     }
 }
开发者ID:packaged,项目名称:helpers,代码行数:21,代码来源:BitWiseGmpTest.php

示例15: summa

function summa($type)
{
    $total_in = gmp_init('0');
    $query = "\n        SELECT SUM(amount) AS sum\n        FROM purses\n        WHERE type='{$type}'\n        ";
    $result = do_query($query);
    $row = get_row($result);
    $v = gmp_init($row['sum']);
    $total_in = gmp_add($total_in, $v);
    $query = "\n        SELECT SUM(amount) AS sum\n        FROM orderbook\n        WHERE type='{$type}' AND status='OPEN'\n        ";
    $result = do_query($query);
    $row = get_row($result);
    if (isset($row['sum'])) {
        $v = gmp_init($row['sum']);
        $total_in = gmp_add($total_in, $v);
    }
    $query = "\n        SELECT SUM(amount) AS sum\n        FROM requests\n        WHERE curr_type='{$type}' AND req_type='WITHDR' AND status='VERIFY'\n        ";
    $result = do_query($query);
    $row = get_row($result);
    if (isset($row['sum'])) {
        $v = gmp_init($row['sum']);
        $total_in = gmp_add($total_in, $v);
    }
    $total_in = gmp_strval($total_in);
    $total_out = gmp_init('0');
    $query = "\n        SELECT SUM(amount) AS sum\n        FROM requests\n        WHERE curr_type='{$type}' AND req_type='DEPOS' AND status='FINAL'\n        ";
    $result = do_query($query);
    $row = get_row($result);
    if (isset($row['sum'])) {
        $v = gmp_init($row['sum']);
        $total_out = gmp_add($total_out, $v);
    }
    $query = "\n        SELECT SUM(amount) AS sum\n        FROM requests\n        WHERE curr_type='{$type}' AND req_type='WITHDR' AND status='FINAL'\n        ";
    $result = do_query($query);
    $row = get_row($result);
    if (isset($row['sum'])) {
        $v = gmp_init($row['sum']);
        $total_out = gmp_sub($total_out, $v);
    }
    $total_out = gmp_strval($total_out);
    echo "{$type} = {$total_in}\t  {$total_out}\n";
    if (gmp_cmp($total_in, $total_out) != 0) {
        echo "*********** MISMATCH ****************\n";
    }
}
开发者ID:martinkirov,项目名称:intersango,代码行数:44,代码来源:summa.php


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