Source: https://www.math.u-bordeaux.fr/~cbachocb/Enseignements/Crypto-Licence/DM1.pdf