As previously mentioned, we have to find difficult arithmetic problems on which to base our security protocol. Most current security approaches come down to the problem of finding the prime factors of a large integer: since Antiquity, we have been trying to do this efficiently, and no solution has been found so far.
One must therefore be able to find two large original prime numbers, and make their product. Our method will be all the more secure as it will be difficult to find the prime factors of this product.
To obtain a list of prime numbers below $N$, one can proceed as follows:
You are asked :
If $n$ is prime, then $n$ divides $a^n-a, a>1$.
In other words, $a^n \equiv a [n].$.
To obtain a large prime number, the idea is to draw a large number of digits, concatenate them as a number, and then test if this number is prime.
The problem with Fermat's theorem is that the implication is in the wrong direction: one would want something of the form "if such and such a property, then the number is prime", as for example in Wilson's theorem. However :
You are asked to implement, in the sensor, a first probabilistic primality test based on Fermat. You can do this by :
Miller-Rabin is, in a way, a refinement of the above. It is once again a probabilistic test of primacy, but for which the risk of being wrong never happens in practice. This test is very effective in measuring the primality of large integers.
Its detailed explanation is beyond the scope of this course. We just ask you to make an implementation in your library for the pyboard, using the code found here. You will be able to check, in a classical python console, that many prime numbers are produced, using the isprime function of numpy.