I have defined the following function in Mathematica to get a SET OF m
SETS (these sets are the codes {p,q,d,e,n}
for the encryption system RSA
.):
RSA[m_] :=
Table[
Module[{prime, p, q, k, factors, d, e, n,ans},
prime = RandomPrime[{2, 10^2}, 2]; p = prime[[1]]; q = prime[[2]];
k = (p - 1)*(q - 1) + 1; factors = FactorInteger[k];
d = RandomChoice[factors][[1]]; e = k/d; n = p*q;
ans = {p, q, d, e, n}; ans],
{i, 1, m}];
The problem is that although it is not very probable, these sets can be repeated, and I would like to avoid this case, but I have no idea. I have tried using the Mathematica function Union
, in which reapeted sets wouldn't be included, but I don't know how to add more in order to get just m elements (sets).