Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invmod(p, q) can wrongly fail #58

Open
hvds opened this issue Jan 24, 2022 · 1 comment
Open

invmod(p, q) can wrongly fail #58

hvds opened this issue Jan 24, 2022 · 1 comment

Comments

@hvds
Copy link
Contributor

hvds commented Jan 24, 2022

Hi Dana, how's the release coming along? :)

My code just hit this today under MPU-0.73:

% cat t
use strict;
use warnings;
use Math::GMP;
use Math::Prime::Util qw{ invmod };

my $p = Math::GMP->new(1589) ** 6;
my $q = Math::GMP->new(93) ** 6;
print "p=$p, q=$q\n";

my $i1 = invmod(-$p, $q);
print "i1=@{[ $i1 // '<undef>' ]}\n";

my $i2 = invmod(-$p % $q, $q);
print "i2=@{[ $i2 // '<undef>' ]}\n";

my $prod = (-$p * $i2) % $q;
print +($prod == 1) ? "i2 ok\n" : "i2 not ok\n";
% perl t
p=16096942149150081961, q=646990183449
i1=<undef>
i2=25493952356
i2 ok
% 

I haven't looked into it yet (nor tested it against the latest github code), and it's easy enough to work around, but I assume it shouldn't be doing that - i1 should get the same answer as i2.

Hugo

@trizen
Copy link
Contributor

trizen commented Jan 24, 2022

I tested the code against the latest github code and it appears that the issue has been fixed:

p=16096942149150081961, q=646990183449
i1=25493952356
i2=25493952356
i2 ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants