Code covered by the BSD License  

Highlights from
modinv(x, N)

3.0

3.0 | 2 ratings Rate this file 2 Downloads (last 30 days) File Size: 1.2 KB File ID: #23802

modinv(x, N)

by Steven Gregory

 

16 Apr 2009 (Updated 27 Apr 2009)

Computes multiplicative inverse of x modulo N

| Watch this File

File Information
Description

Using variable precision integers, computes y such that
mod(x*y, N) == 1 is TRUE.

MATLAB release MATLAB 7.2 (R2006a)
Other requirements John D'Errico's VPI suite of files.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (6)
16 Apr 2009 John D'Errico

8-)

25 Mar 2011 fisher

It seems the function is not completed. Some of the sub functions are not defined.

25 Mar 2011 Steven Gregory

This module, and any others tagged vpi, require John D'Errico's vpi suite of programs. As listed under "Other requirements".

04 Oct 2011 Nanthini

hi i used your modinv function the program is given below

a= input('Please input a vpi number: ','s');
f=vpi(a);
e=nextprime(f);
d=modinv(vpi(e),vpi('10641850662478050775300838063179295326495311244216495264720240475083278486076641392553755151560108920715482251286670052918931640724590870256900164694640700350819991051744179236211734410573176997209650364459122853571059016377162766023444746540824998138258407652750335008405190180074534476000047130911251907798499684299595857553973251414375363400538217657736630155539478633941291033068252991757356109381559827851766572043021641234224646877436996703749498922980940934823068060307119029571082281451848485625212652649192958086070122442905758802027526434401481214679307640378414874445695431164943304505187971133265334792817439396071458544945483012899852152133643802968883876'));
disp(d);

For this i got output like this
Please input a vpi number: 78932798709875897985798239632962
  -521510991024643651399669163491559260313526227617474791885763042505857
664977385561168456997539245033945323802087603744630561104830663196609729
027089135771997781645557505192562664968792519121732948128932325159571954
569243970932264987495930313006348655908194700156297275119605911309222114
908823626023733986115222495783413651229506339868566939895630365025986535
210301856596816873363852149927397763766351293662529444692448582845757980
384646334165589784970212497170690948718484808254845836093034729679728997
842249100410667287038983219348274168413156054636466230079069467248343347
119255305695342572748941360728235707527909213139658151308501287396735563
0404723105668513063513

i got negative value for variable 'd'....
The result should be in positive but the result displayed by this function is negative please suggest some idea to rectify this error....

05 Oct 2011 Steven Gregory

It's not an error. The number returned is y such that mod(x*y, N) == 1 is TRUE. If you want it to be a positive number, then add N to it.

10 Oct 2011 Nanthini

thanks Steven...i got it...

Please login to add a comment or rating.
Updates
27 Apr 2009

Rewrote the code to exploit (the new) VPIs matrix-related functions.

Tag Activity for this File
Tag Applied By Date/Time
vpi Steven Gregory 16 Apr 2009 14:32:18
mathematics Steven Gregory 16 Apr 2009 14:32:19
modular arithmetic Steven Gregory 16 Apr 2009 14:32:19
mod Steven Gregory 16 Apr 2009 14:32:19
vpi Alberto 13 Nov 2011 02:40:58

Contact us at files@mathworks.com