how do those banks find huge primes that have like 30+ digits? do they generate them over time, store them and use them after?
It's called the Miller-Rabin primality test.It's what's known as a probabilistic test; meaning that there is a change that the algorithm is actually wrong.
In the case of this algorithm: If it returns that the number is
not a prime, then it is guaranteed to not be a prime. If it returns true, that it is a prime, then there's actually a very small chance that it isn't a prime and is composite.
The thing about it is that the chance is very small, to be exact there's a 1/4
k chance that it's wrong, where k is the number of times you run the test. This means that if you run the test 10 times then there's a one in one million chance that it's not a prime, if you run it 20 times that means there's a one in one
trillion chance that the number isn't a prime.
Please note that in order for modular exponentiation to work, the variable type you're using has to be able to hold the entirety of the number modulus * modulus without overflow.
And I actually just got it working now in C#, it's absolutely blazingly fast.
And thanks for the good luck :)