• PHP Video Tutorials

PHP gmp_invert() Function



Definition and Usage

The gmp_invert() function will return the modular inverse of given GMP numbers.

Description

The gmp_invert() calculates the inverse of a modulo b GMP numbers.

The module inverser for any given number is calculated as follows −

  • A * X = 1 (mod B) , Here the value of X has to be in the following range = {0,1,2,...B-1}

For example the numbers 3, 7 the modular inverse will be

  • (3*5) mod 7 = 1 , so the modular inverse of 3 and 7 is 5 and also the value of 5 is in the range of {0,1,2,3,4,5,6}

Syntax

gmp_invert ( GMP $a , GMP $b ) : GMP

Parameters

Sr.No Parameter & Description
1

a

It can a GMP resource number , a gmp object or a numeric string.

2

b

It can a GMP resource number , a gmp object or a numeric string.

Return Values

PHP gmp_invert() function returns a GMP number or false on failure.

PHP Version

This function will work from PHP Version greater than 5.0.0.

Example 1

Working of gmp_invert −

<?php
   $invert = gmp_invert("3", "7");
   echo "The modular inverse of 3 and 7 is : ".$invert;
?>

This will produce following result −

The modular inverse of 3 and 7 is : 5

Example 2

Working of gmp_invert −

<?php
   $a = gmp_init(3);  
   $b = gmp_init(11); 
   $gmp_number = gmp_invert($a, $b); 
   echo "The modular inverse of 3 and 11 is :".$gmp_number;
?>

This will produce following result −

The modular inverse of 3 and 11 is :4
php_function_reference.htm
Advertisements