To talk about the RSA algorithm we first need a little more theory.
Fermat's little theorem
Statement
Fermat's little theorem
For any prime number and we have
Proof
Note if is a multiple of the statement is true as both sides are zero. It suffices to prove this for as all other integers are congruent to one of these mod . Moreover, we only need to show (mod ).
Therefore by multiplying the entries in together we have
However as for is coprime to from modular multiplicative inverse existence lemma. We know therefore has a multiplicative inverse mod . So we have
as desired.
Note if if and only if and as and are coprime. Therefore
Missing \begin{array} or extra \end{array}\ \{y \in \mathbb{N} \ \vert \ 0 < x \leq n, \ gcd(x,n) = 1 \} \end{array} \mapsto \left \{b(x,y) \in \mathbb{N} \ \Bigg \vert \begin{array} \ 0 < b(x,y) \leq mn, \\ \ gcd(b(x,y),mn) = 1 \end{array} \right \}$$ and we have $$\phi(mn) = \phi(m) \phi(n).$$ ## Claim 2 >[!important] Claim 1 > >If $p$ is prime and $k \geq 1$, then >$$\phi(p^k) = p^k - p^{k-1} = p^{k-1}(p - 1) = p^k\left ( 1 - \frac{1}{p} \right ).$$ ## Proof of Claim 2 As $p$ is [[Prime|prime]] we know the positive divisors of $p^k$ are powers of $p^i$ for $0 \leq i \leq k$. Therefore of $gcd(p^k, x) > 1$ we know $x$ will have to be a multiple of $p$. So $x = mp$ with $m \in \mathbb{Z}_{\not = 0}$ and for $0 < x < p^k$ we have $0 < m \leq p^{k-1}$. So $$\phi(p^k) = \big \vert \left \{x \in \mathbb{N} \ \vert \ 0 < x \leq p^k, \ gcd(x,p^k) = 1 \right \} \ \big \vert = p^k - p^{k-1}$$ giving the desired result.Link to original
Which as a corollary has for two distinct prime numbers.
The first stage of the RSA algorithm is to select two random -bit primes. To do this we first select a random number by randomly selecting each bit in this number.
As primes are dense the probability that this number is prime is . So we just keep repeating ourselves until we hit a prime number.
random_prime(n): Input: n the length of the number in bits. Output: A prime number that has n-bits.1. Select a random n-bit number.2. If it is prime return it3. Go back to step 1.
However, the Fermat witness constructed in the proof are not dense in the numbers between to . We need the existence of non-trivial Fermat witness to guarantee this.
Pick a non-trivial Fermat witness. Then for any such that
it has a twin where
Note as we are just multiplying by which is a bijection on integers mod we have that at most half of are not Fermat witnesses.
We want to use the above to test the primality of a number randomly.
Primality Test(r) Input: An postive integer r. Output: If the algorithm thinks r is prime or not1. Choose z_1, ..., z_k randomly from {1,2, ... , r-1}2. For i = 1 -> k 1. Compute z_i^{r-1} (mod r)3. If for all i, z_i^{r-1} = 1 (mod r) then output r is prime4. Otherwise output r is composite
This algorithm is always correct if is prime. However, there are two cases where we can be unlucky:
is a Carmichael number, then it is quite likely we will return it is prime, or
We are unlucky is composite and not a Carmichael number then
We can adapt this algorithm to search for non-trivial square roots of 1 mod that only exist when is not prime also. This doesn’t take into account Carmichael numbers so makes the algorithm slightly safer.