Code:
keygen[keybitlength_] :=
Module[{kbl, kbl1, pPrime, qPrime, nKey, phiOFn, eKey, dKey},
kbl = 2^(keybitlength/2);
kbl1 = 2^(keybitlength/2 - 1);
pPrime = RandomPrime[{kbl1, kbl}];
qPrime = RandomPrime[{kbl1, kbl}];
nKey = pPrime*qPrime;
phiOFn = (pPrime - 1) (qPrime - 1);
While[eKey = RandomPrime[{2, phiOFn}]; ! CoprimeQ[eKey, phiOFn]];
dKey = PowerMod[eKey, -1, phiOFn];
{{eKey, nKey}, {dKey, nKey}}]
The part I don't understand is this (specifically the While statement. to me it seems like it lacks a body?):
While[eKey = RandomPrime[{2, phiOFn}]; ! CoprimeQ[eKey, phiOFn]];
dKey = PowerMod[eKey, -1, phiOFn];
{{eKey, nKey}, {dKey, nKey}}]
While eKey is a random Prime between 2 and phiOFn and not Coprime with phiOFn? To my knowledge eKey and phiOfN should be Coprime for RSA encryption to work.