I want to implement RSA, and for this I need to generate e, which should be gcd(e, ø(n)) = 1 and 1 < e < ø(n), and also must be very close in size to ø(n). My alg. the first two steps are discussed below, but the generated number is quite small. How can I create a larger one?
p = new BigInteger(512, 15, new Random());
q = new BigInteger(512, 15, new Random());
r = new BigInteger(512, 15, new Random());
n = p.multiply(q);
n = n.multiply(r);
ø_n = p.subtract(BigInteger.valueOf(1));
ø_n = ø_n.multiply(q.subtract(BigInteger.ONE));
ø_n = ø_n.multiply(r.subtract(BigInteger.ONE));
do {
e = new BigInteger(2 * 512, new Random());
} while
((e.compareTo(ø_n) >= 0)
||
(e.gcd(ø_n).compareTo(BigInteger.ONE) != 0));
Check the loop while, everything else is just initialization.
source
share