Java-Gaming.org Hi !
 Featured games (91) games approved by the League of Dukes Games in Showcase (755) Games in Android Showcase (229) games submitted by our members Games in WIP (842) 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 2469 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

JGO Kernel

Medals: 517

 « 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

JGO Kernel

Medals: 517

 « 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

JGO Kernel

Medals: 517

 « 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

JGO Kernel

Medals: 517

 « 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

 DesertCoockie (36 views) 2018-05-13 18:23:11 nelsongames (82 views) 2018-04-24 18:15:36 nelsongames (74 views) 2018-04-24 18:14:32 ivj94 (755 views) 2018-03-24 14:47:39 ivj94 (85 views) 2018-03-24 14:46:31 ivj94 (626 views) 2018-03-24 14:43:53 Solater (101 views) 2018-03-17 05:04:08 nelsongames (182 views) 2018-03-05 17:56:34 Gornova (408 views) 2018-03-02 22:15:33 buddyBro (1068 views) 2018-02-28 16:59:18
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 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