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


PHP gmp_gcd函数代码示例

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


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

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

示例2: getGCD

 public static function getGCD($numberA, $numberB)
 {
     if (!self::isInteger($numberA) | !self::isInteger($numberB)) {
         throw new \InvalidArgumentException("GCD number must be an integer");
     }
     if (function_exists("gmp_gcd")) {
         return gmp_intval(gmp_gcd($numberA, $numberB));
     }
     if ($numberA == 0 || $numberB == 0) {
         return max(abs($numberA), abs($numberB));
     }
     $r = $numberA % $numberB;
     return $r != 0 ? self::getGCD($numberB, $r) : abs($numberB);
 }
开发者ID:thelia,项目名称:math-tools,代码行数:14,代码来源:GCD.php

示例3: getSizeRatio

 /**
  * Gets crop's size.
  *
  * @param \Drupal\image\Entity\ImageStyle $image_style
  *   The image style.
  *
  * @return string
  *   The ratio to the lowest common denominator.
  */
 public function getSizeRatio(ImageStyle $image_style)
 {
     // Get the properties of this ImageStyle.
     $properties = $this->getImageStyleSizes($image_style);
     if (isset($properties) && (!empty($properties['width']) || !empty($properties['height']))) {
         $gcd_object = gmp_gcd($properties['width'], $properties['height']);
         $gcd = gmp_strval($gcd_object);
         if (!empty($gcd) && $gcd != '1') {
             return round($properties['width'] / $gcd) . ':' . round($properties['height'] / $gcd);
         } elseif (!empty($gcd)) {
             return $gcd . ':' . $gcd;
         } else {
             return NULL;
         }
     }
 }
开发者ID:el22or,项目名称:image_widget_crop,代码行数:25,代码来源:ImageWidgetCrop.php

示例4: __construct

 /**
  * @param int $nominator
  * @param int $denominator
  */
 public function __construct($nominator, $denominator = 1)
 {
     if ($nominator == 0) {
         $denominator = 1;
     } else {
         if (function_exists('gmp_gcd')) {
             $gcd = gmp_intval(gmp_gcd((string) $nominator, (string) $denominator));
             $nominator /= $gcd;
             $denominator /= $gcd;
         } else {
             if ($nominator / $denominator == (int) ($nominator / $denominator)) {
                 $nominator = $nominator / $denominator;
                 $denominator = 1;
             }
         }
     }
     $this->denominator = $denominator;
     $this->nominator = $nominator;
 }
开发者ID:groupcash,项目名称:php,代码行数:23,代码来源:Fraction.php

示例5: gcd

 /**
  * Greatest cummon divisor
  */
 function gcd($a, $b)
 {
     if (function_exists('gmp_gcd')) {
         $gcd = gmp_strval(gmp_gcd($a, $b));
         $this->addDebug("gcd-version", "gmp_gcd:" . $gcd);
         return $gcd;
     } else {
         $gcd = $this->my_gcd($a, $b);
         $this->addDebug("gcd-version", "my_gcd:" . $gcd);
         return $gcd;
     }
 }
开发者ID:vollyimnetz,项目名称:crop-thumbnails,代码行数:15,代码来源:editor.php

示例6: addPoints

 public function addPoints(array $pt1, array $pt2)
 {
     $p = $this->p;
     if (gmp_cmp($pt1['x'], $pt2['x']) == 0 && gmp_cmp($pt1['y'], $pt2['y']) == 0) {
         return $this->doublePoint($pt1);
     }
     $gcd = gmp_strval(gmp_gcd(gmp_sub($pt1['x'], $pt2['x']), $p));
     if ($gcd != '1') {
         throw new \Exception('This library doesn\'t yet supports point at infinity. See https://github.com/BitcoinPHP/BitcoinECDSA.php/issues/9');
     }
     // SLOPE = (pt1Y - pt2Y)/( pt1X - pt2X )
     // Equals (pt1Y - pt2Y) * ( pt1X - pt2X )^-1
     $slope = gmp_mod(gmp_mul(gmp_sub($pt1['y'], $pt2['y']), gmp_invert(gmp_sub($pt1['x'], $pt2['x']), $p)), $p);
     // nPtX = slope^2 - ptX1 - ptX2
     $nPt = array();
     $nPt['x'] = gmp_mod(gmp_sub(gmp_sub(gmp_pow($slope, 2), $pt1['x']), $pt2['x']), $p);
     // nPtX = slope * (ptX1 - nPtX) - ptY1
     $nPt['y'] = gmp_mod(gmp_sub(gmp_mul($slope, gmp_sub($pt1['x'], $nPt['x'])), $pt1['y']), $p);
     return $nPt;
 }
开发者ID:hartmantam,项目名称:php-license-system,代码行数:20,代码来源:ECDSA.php

示例7: gmp_divexact

$div1 = gmp_divexact("10", "2");
echo gmp_strval($div1) . "\n";
// gmp_fact
$fact1 = gmp_fact(5);
// 5 * 4 * 3 * 2 * 1
echo gmp_strval($fact1) . "\n";
$fact2 = gmp_fact(50);
// 50 * 49 * 48, ... etc
echo gmp_strval($fact2) . "\n";
// gmp_gcd
$gcd = gmp_gcd("12", "21");
echo gmp_strval($gcd) . "\n";
// gmp_gcdext
$a = gmp_init(12);
$b = gmp_init(21);
$g = gmp_gcd($a, $b);
$r = gmp_gcdext($a, $b);
$check_gcd = gmp_strval($g) == gmp_strval($r['g']);
$eq_res = gmp_add(gmp_mul($a, $r['s']), gmp_mul($b, $r['t']));
$check_res = gmp_strval($g) == gmp_strval($eq_res);
if ($check_gcd && $check_res) {
    $fmt = "Solution: %d*%d + %d*%d = %d\n";
    printf($fmt, gmp_strval($a), gmp_strval($r['s']), gmp_strval($b), gmp_strval($r['t']), gmp_strval($r['g']));
} else {
    echo "Error while solving the equation\n";
}
// gmp_hamdist
$ham1 = gmp_init("1001010011", 2);
$ham2 = gmp_init("1011111100", 2);
echo gmp_hamdist($ham1, $ham2) . "\n";
echo gmp_popcount(gmp_xor($ham1, $ham2)) . "\n";
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:mostInOne.php

示例8: gcd

 public static function gcd(Gmp $a, Gmp $b)
 {
     return new Gmp(gmp_gcd($a->getNumber(), $b->getNumber()));
 }
开发者ID:juno,项目名称:code-snippet,代码行数:4,代码来源:Gmp.php

示例9: decript

    public function decript()
    {
        $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");
        if ($pesan != "") {
            $hasildekripsi = deskripsi($pesan, $d, $n);
            ?>
		
		<li class="left clearfix">
               
                <div class="chat-body clearfix">
                    <p class="bg-warning pesan">
                        <?php 
            echo $hasildekripsi[1];
            ?>
                    </p>
                </div>
            </li>
		
		<?php 
        } else {
            echo "<li class=\"right clearfix\">\r\n               \r\n                <div class=\"chat-body clearfix\">\r\n                    <p class=\"bg-warning pesan\">\r\n                        Belum ada data\r\n                    </p>\r\n                </div>\r\n            </li>";
        }
    }
开发者ID:senusop,项目名称:ci,代码行数:65,代码来源:deskripsi.php

示例10: lcm

 /**
  * Return Least Common Multiple of two numbers
  * @param int $a
  * @param int $b
  * @return int
  */
 private function lcm($a, $b)
 {
     return gmp_abs(gmp_div_q(gmp_mul($a, $b), gmp_gcd($a, $b)));
 }
开发者ID:chippyash,项目名称:strong-type,代码行数:10,代码来源:GMPComplexType.php

示例11: reduce

 /**
  *
  * Reduce this number to it's lowest form
  */
 protected function reduce()
 {
     $gcd = gmp_gcd($this->value['num']->gmp(), $this->value['den']->gmp());
     if (gmp_cmp($gcd, 1) > 0) {
         $this->value['num']->set(gmp_div_q($this->value['num']->gmp(), $gcd));
         $this->value['den']->set(gmp_div_q($this->value['den']->gmp(), $gcd));
     }
 }
开发者ID:chippyash,项目名称:strong-type,代码行数:12,代码来源:GMPRationalType.php

示例12: question6

function question6()
{
    $rand = rand(1, 100);
    $rand1 = rand(1, 100);
    $enonce = "PGCD(" . $rand . "," . $rand1 . ") ?";
    $bonne = gmp_gcd($rand1, $rand);
    $mauvaise_list = array(0 => $bonne - rand(1, 5), 1 => $bonne + rand(1, 5), 2 => $bonne - rand(6, 10), 3 => $bonne - rand(6, 10));
    shuffle($mauvaise_list);
    $bonne_rep = rand(0, 3);
    $retour = array();
    for ($i = 0; $i < 4; $i++) {
        if ($i == $bonne_rep) {
            $retour[$i] = $bonne;
        } else {
            $retour[$i] = $mauvaise_list[$i];
        }
    }
    return array("enonce" => $enonce, "bonne_rep" => $bonne_rep, "reponses" => $retour);
}
开发者ID:cmarquay,项目名称:evolution,代码行数:19,代码来源:ER_quiz_rand.php

示例13: gmp_mul

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);
echo "gmp mull :" . $n;
$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;
    }
开发者ID:senusop,项目名称:ci,代码行数:31,代码来源:rsa.php

示例14: getLargestCommonFactor

 /**
  * use PHP GMP function to get the largest common factor
  */
 public function getLargestCommonFactor()
 {
     $gcd = gmp_gcd($this->num1, $this->num2);
     $f = gmp_strval($gcd);
     $this->largestFactor = (int) $f;
 }
开发者ID:chenyinl,项目名称:findCommonFactors,代码行数:9,代码来源:CommonOddFactor.php

示例15: _getItemsData

 protected function _getItemsData()
 {
     if ($this->usePriceRanges()) {
         $data = array();
         if ($this->getInterval()) {
             return $data;
         }
         $priceRanges = $this->_getPriceRanges();
         $priceRanges = explode(';', $priceRanges);
         foreach ($priceRanges as $priceRange) {
             $range = explode('-', $priceRange);
             $min = (int) $range[0];
             $max = (int) $range[1];
             if (0 === $min) {
                 // from 0 to x
                 $counts = $this->getRangeItemCounts($max);
                 $count = 0;
                 if (array_key_exists(1, $counts)) {
                     $count = $counts[1];
                 }
             } elseif (0 === $max) {
                 // from x to infinite
                 $counts = $this->getRangeItemCounts($min);
                 if (array_key_exists(1, $counts)) {
                     unset($counts[1]);
                 }
                 $count = array_sum($counts);
             } else {
                 // from x to y
                 $range = array($min, $max);
                 $min = min($range);
                 $max = max($range);
                 if (extension_loaded('gmp') && function_exists('gmp_gcd')) {
                     $gcd = gmp_intval(gmp_gcd($min, $max));
                 } else {
                     $gcd = gcd($min, $max);
                 }
                 $counts = $this->getRangeItemCounts($gcd);
                 $count = 0;
                 for ($i = (int) ($min / $gcd) + 1; $i * $gcd <= $max; $i++) {
                     if (array_key_exists($i, $counts)) {
                         $count += $counts[$i];
                     }
                 }
             }
             if (0 < $count) {
                 $range = explode('-', $priceRange);
                 $data[] = array('label' => $this->_renderRangeLabel($range[0], $range[1]), 'value' => $priceRange, 'count' => $count);
             }
         }
         return $data;
     }
     return parent::_getItemsData();
 }
开发者ID:xiaoguizhidao,项目名称:magento-customize-price-filter,代码行数:54,代码来源:Price.php


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