Source: https://www.jsums.edu/nmeghanathan/files/2015/08/CSC541-Fall2015-Module-3-NumberTheory-RSA.pdf