so I'm trying to understand this code for Miler Rabin test.
I saw a bunch of videos explaining the general idea mathematically,
https://www.youtube.com/watch?v=zmhUlVck3J0
(here I understood that if n divides one of the terms then it's prime, if it doesn't divide any of the terms then it's composite, but I didn't really understand why we have to get the exponent to an odd number, like I kind of get the idea but not really)
https://www.youtube.com/watch?v=qdylJqXCDGs
(I understood in this video the idea mathematically more, I also understood that the main point is
if a^exp ≡ 1 (mod n) then it's composite
if it's a^exp ≡ -1 (mod n) it's probably prime.
I also watched a videio explaining how ro implemet in python.
https://www.youtube.com/watch?v=-BWTS_1Nxao
Here is the main problem that I don't understand
in the video he talks about it from about minute 8, it's the second condition where he returns true meaning the number is composite and I don't undertand why the condition lets the number be composite espisially that he says that a^exp ≡ -1 (mod n) is eqivelant to a^exp ≡ -n-1 (mod n) how and why
and if it's equivilant why is that in other videios they say if
a^exp ≡ -1 (mod n) means that the number is prime?
so I have a similer code written in java cuz I'm used to java more:
the code is in the reply message
Ever wanted to know if a number was prime but thought trial division was too tedious?
The Miller-Rabin primality test is one of many tests that can determine whether a given integer is prime or not.
External Resources
Miller-Rabin: https://crypto.stanford.edu/pbc/notes/numbertheory/millerrabin.html
Fermat's Little Theorem: https://mathworld.wo...
Here's a second (better) example for how to use the Miller-Rabin primality test.
This video has me coding up the Miller-Rabin primality test so that we can see it in action.
This video explains all the necessary parts for determining whether a given integer is prime. For an explanation of how to derive a large prime, or for a time complexity analysis, watch part 2: https://youtu.be/9sUYqDAt_gs.
If you haven't already, go wa...