For security of our cryptosystems, we will need to choose a large random prime number (secret keys) efficiently.
Les's assume we need a prime number which is 1000bits.
Before choosing prime numbers, we need to find an algorithm to check a number whether is prime numbers or not, so we use the algorithm that called Theorem(Euler/Fermat Theorem), let me introduce the theory.
I will introduce a notation firstly, Φ(n) means to find the number of prime numbers which are less than n, for example:
Φ(5) = {1,2,3,4} = 5
Φ(8) = {1,2,3,4,5,6,7} --> {1,3,5,7} = 4
BTW, for any prime number Φ(n) = n - 1
And then we have: for any prime number p,q, and n = p*q then
Φ(n) = Φ(p*q)= (p-1) * (q-1) = p*q-(p+q-1)
For example,
p = 3, q = 7
n = 21
not (Φ(3} and Φ(12)) = {0,0,3,6,7,9,14,15,18}
Φ(3) and Φ(12) = {1,2,4,5,8,10,11,13,16,17,19,20} = 12
Φ(n) = Φ((3-1)*(7-1)) = 12
Then, Let me introduce the theory.
- Theorem(Euler/Fermat Theorem): if M and n are relatively prime integers then and y(mod Φ(n)) = 1 for M < n then M^(Φ(n)) mod n = 1.
Consequently, we have:
- M^(Φ(n)) mod n = M(Φ(n))*M mod n = 1* M mod n = M
- if y mod(mod Φ(n)) = 1, i.e y = Φ(n) * k + 1 for interget k then
- M^y mod n = M^(Φ(n)*k+1) mod n = (M^(Φ(n)))^k * M mod n = 1^k * M ^1 mod n = M
For conclusion, we have: M^(Φ(n)) mod n = 1(If M and n are relatively prime number)
(That's important, because that's the algorithem we use to test large random prime number)
Then, the question becomes easier, the way we choose a large prime number is choosing a random number (P). We assume that p is a prime number, and choose multiple numbers to confirm with our assuming by implementing the algorithm (Theorem).
If for all we have a^(p-1) mod p = 1, which means the number p is a prime number.
Does it very hard to get a large prime number?
Actually, the probability of a random number is a prime number is 1/(ln(2)*L) ≈ 1/(0.693*L) ≈ 1/693
(L is the bits of a prime number we need, in there the L is 1000 because we need 1000bits prime number)
That's all how we generate a large prime number for cipher security.
Thanks for reading.