I am supposed to make a basic RSA encryption/decryption code, where I am only given e.
I wrote this code to randomly generate two primes and then find their totient. But the totient is supposed to not be co-prime with e which is given as 65537. So this code would technically return a good value eventually, but in reality it would take ages. Please help me speed it up and/or make suggestions on how it can be improved in general.
def primeGen(lim): """Generates all primes up to a certain limit (lim)""" fnl= primes= p=0 for n in range(2,lim+1): fnl.append(n) for v in fnl: p=0 for i in range(2,v): if (v%i==0): p=1 break if p==0 and i==(v-1): primes.append(v) return primes import random def randomPrimeGen(lim): """Generates a single random prime number using primeGen(lim)""" M=(len(primeGen(lim))-1) randomPrime=(primeGen(lim)[random.randint(int(M/10),M)]) return randomPrime def modtot(): e=65537 totient=1 GCD=gcd(e,totient) while GCD==1: p=randomPrimeGen(30000) q=randomPrimeGen(30000) n=p*q totient=((p-1)*(q-1)) GCD=gcd(e,totient) print(GCD, totient) return n, totient