Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (604) Games in Android Showcase (171) games submitted by our members Games in WIP (654) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 calculating an inverse multiplicative modulus in java...  (Read 734 times) 0 Members and 1 Guest are viewing this topic.
lcass
 « Posted 2014-08-21 23:14:07 »

Yer I have the kind of feeling this is going to go well or be very painful.
So I cant find any detailed example that explains this well , if someone would be able to just show me how it works with an example of code that calculates for example d = inverse multiplicate modulus of x(mod d)
Roquen
 « Reply #1 - Posted 2014-08-22 07:56:42 »

What's with matrix inversion questions...what do you really want to do?  What's the field of the matrix elements?
pjt33

« JGO Spiffy Duke »

Medals: 40
Projects: 4
Exp: 7 years

 « Reply #2 - Posted 2014-08-22 09:25:24 »

@lcass, are you guaranteed that d is a prime? If not, the inverse may not exist. If it does exist, it can be found efficiently with the extended Euclidean algorithm. That page has a section on multiplicative inverses.
lcass
 « Reply #3 - Posted 2014-08-22 09:28:18 »

Modulus inversion , not matrix inversion , So for instance if I have something of the form ax = 1 (mod(n)) how do I solve for x (in an algorithm) I know you turn it to the form of a fraction by performing a^-1 = x (mod(n)) then you find a value of x that works , however running through every value of x (for values in the long size) is difficult.
lcass
 « Reply #4 - Posted 2014-08-22 09:28:55 »

@lcass, are you guaranteed that d is a prime? If not, the inverse may not exist. If it does exist, it can be found efficiently with the extended Euclidean algorithm. That page has a section on multiplicative inverses.
Thanks for that info , yes I have made a prime number generator.
Roquen
 « Reply #5 - Posted 2014-08-22 09:47:44 »

Bad me. There's a modulo inverse for all odd integers.  This is newton's method instead:  https://github.com/roquendm/JGO-Grabbag/blob/master/src/roquen/math/Int32.java
Roquen
 « Reply #6 - Posted 2014-08-22 09:51:09 »

I think I need to go have a drink or something.  Trouble with reading comprehension.
pjt33

« JGO Spiffy Duke »

Medals: 40
Projects: 4
Exp: 7 years

 « Reply #7 - Posted 2014-08-22 11:07:46 »

Bad me. There's a modulo inverse for all odd integers.
No, there's a modulo inverse for all numbers which are coprime with the modulus. Hence the link with Euclid's algorithm for finding gcd. (I'm not sure whether you realised this and that's why the bit about needing a drink, but even if you have it might be helpful for other people reading the thread).

I think your linked code is calculating inverses modulo 2^32 for odd integers, but the Javadoc isn't clear enough for me.

Thanks for that info , yes I have made a prime number generator.
I should add that in general you can use Euler's theorem, and for primes that's Fermat's little theorem: a^(p-1) == 1 (mod p) provided that a is not a multiple of p. So if you already have a modular exponentiation function and you don't have an extended Euclid function, that's an alternative approach. I think they should have the same asymptotic complexity.
Roquen
 « Reply #8 - Posted 2014-08-22 11:39:19 »

Indeed it's mod 2^32.  I should update the docs.
lcass
 « Reply #9 - Posted 2014-08-22 11:45:49 »

I use a nifty little function for generating long primenumbers , I am still finding it really difficult to understand how inverse modulus works so if I plonk this down would someone be able to give an explanation of it?
So say i need to calculate D , D = inverse multiplicate modulus of e % n; or d = e^-1 %n;
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 bilznatch (26 views) 2015-08-04 11:03:17 SHC (44 views) 2015-08-01 03:58:20 Jesse (25 views) 2015-07-29 04:35:27 Riven (48 views) 2015-07-27 16:38:00 Riven (26 views) 2015-07-27 15:35:20 Riven (28 views) 2015-07-27 12:26:13 Riven (19 views) 2015-07-27 12:23:39 BurntPizza (42 views) 2015-07-25 00:14:37 BurntPizza (56 views) 2015-07-24 22:06:39 BurntPizza (35 views) 2015-07-24 06:06:53
 theagentd 50x wessles 48x basil_ 33x KaiHH 26x Riven 21x orangepascal 17x mooman219 17x bornander 16x ags1 16x KudoDEV 13x CelestialCreator 11x princec 11x klaus 11x pquiring 11x israelg99 9x Spasi 8x
 List of Learning Resourcesby gouessej2015-07-09 11:29:36How Do I Expand My Game?by bashfrog2015-06-14 11:34:43List of Learning Resources2015-05-31 05:37:30Intersection Methodsby Roquen2015-05-29 08:19:33List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org