(* Random Seed 123456 is not secure, but it allows us to repeat the experiment *)
SeedRandom[123456]
p=RandomPrime[{10^1000,10^1050}];
q=RandomPrime[{10^1000,10^1050}];
NN=p q;
phi = (p-1)(q-1);
GCD[phi,7]

(* GCD[phi,7] is not 1, so he have to try a different value of e *)

GCD[phi,3]

(* We can set e=3 *)
e=3;

(* We can find d s.t. ed = 1 mod N by using the extended GCD algorithm *)
(* Mathematica is clever enough to do this automatically *)
Solve[e x == 1, Modulus->phi]

d=;

Mod [e d, (p-1)(q-1)]

(* Encrypt the message 200, c= m^e mod N *)

m = 200;

PowerMod[m,e,NN]

(* Hm...That doesn't seem too secure  *)

CubeRoot[PowerMod[m,e,NN]]

(* Encrypt a larger message, c= m^e mod N *)

SeedRandom[1234567];
m2= RandomInteger[{10^1500,10^1501}];
c=PowerMod[m2,e,NN]

(* Does it decrypt properly? *)

PowerMod[c,d, NN]-m2

ChineseRemainder[ {Mod[m2+1, p],Mod[m2+1,q]},{p,q}]-m2