Yes, this method can be used in cryptography. RSA encryption involves the finding of huge prime numbers, sometimes on the order of 1024 bits (about 300 digits). The security of RSA depends on the fact that factoring a number that consists of 2 of these prime numbers multiplied together is extremely difficult and time consuming. But for it to work, they must be prime.
It turns out that proving these numbers prime is difficult too. But the Miller-Rabin primality test, one of the primality tests uses by isProbablePrime
, either detects that a number is composite or gives no conclusion. Running this test n
times allows you to conclude that there is a 1 in 2n odds that this number is really composite. Running it 100
times yields the acceptable risk of 1 in 2100 that this number is composite.