php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15835 Problem on function gmp_invert ()
Submitted: 2002-03-02 11:44 UTC Modified: 2002-04-09 16:19 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:3 (100.0%)
From: sama at inf dot ufsc dot br Assigned:
Status: Closed Package: *Math Functions
PHP Version: 4.1.2 OS: Linux - Red Hat 7.2
Private report: No CVE-ID: None
 [2002-03-02 11:44 UTC] sama at inf dot ufsc dot br
The function resource gmp_invert() doesn't work right. It always return zero.

I implemented the extended Euclides algoritm that do exactly the same that this function and, it returned me the right value.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-02 13:29 UTC] elixer@php.net
Please provide a short reproducing script with values that you are using and expected output.

Sean
 [2002-03-02 14:20 UTC] sama at inf dot ufsc dot br
Example:

$x = gmp_init("0x00d2d025ec7e1dbb6d778a52394c988594c57b47d7327a3e676d3a5ca7a5af87c4153c80994cf781f6a9d4a2f0e66d04baffb0059853a8937a895f6d17e76950e1"); // mod
$y = gmp_init("6211846575289879599"); // value

$w = gmp_invert($y,$x);

The $w value should be :

6673516182899846998314488146047624198500176381239637064622226136275029334435034698239463153441869117173460635003602664197747901516108936488872273669129832
 [2002-03-03 06:42 UTC] sander@php.net
I can't get gmp_invert() return anything other than false, but that might be because I have no idea what gmp_invert() does :)
Can you supply some (human understandable) data that does work?
 [2002-03-04 07:30 UTC] sama at inf dot ufsc dot br
gmp_invert() should return the multiplicative inverse (if exist) of a number, module something.

It's the extended Euclidean algorithm. I wrote this code and I can give you. I think there is something wrong to gmp_invert.
 [2002-03-04 09:12 UTC] sander@php.net
Are you sure that the extended Euclidean Algorithm does the same as gmp_invert? The Euclidean Algorithm computes the greatest common divisor, gmp_invert doesn't seem to do that...
Anyway, gmp_invert seems to be broken. I can't get it to return anything else than false.
So I ask you again: can you give me some human understandable data that works or should work?
 [2002-03-04 10:50 UTC] sama at inf dot ufsc dot br
Yes, I'm sure. The "Euclidean Algorithm" computes the greatest common divisor but, the "Extended Euclidean Algorithm" give you the multiplicative inverse.

The multiplicative inverse of 7 module 13 is 2 so, if I use gmp_invert(7,13) it should return 2. 

Ok ?
 [2002-04-09 16:19 UTC] jimw@php.net
This bug has been fixed in CVS.

it was a minor (but obviously crippling) typo. instead of doing gmp_invert(a,b), it was doing gmp_invert(a,a). oops!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 21:01:36 2024 UTC