I am trying to find the encoding number and decoding. I know the basic rules that you need to find, and started trying to create a python program that finds the variable e and variable d from randomly picking the first 150 primes. I did like this:
import random
from primesieve import *
from sympy.solvers import *
from sympy import *
f = 0
choiceOfPrimes = generate_primes(10)
p = random.choice(choiceOfPrimes)
q = random.choice(choiceOfPrimes)
while p == q:
p = random.choice(choiceOfPrimes)
n = p * q
phiN = (p-1) * (q-1)
lista = []
listb = []
for naa in range(1, phiN):
lista.append(naa)
for naaa in range(1, 35):
listb.append(naaa)
e = random.choice(lista)
def finding_d():
global phiN
global e
global f
f = e
abc = []
abc = divmod(phiN, f)
abc1 = f * abc[0]
abc2 = abc[1]
phiN = f * abc1 + abc2 # phiN = f * {how many it goes in} + {remainder}
abc3 = divmod(f, abc2)
f = abc2 * abc3[0] + abc3[1] # (moved f to phiN) and (remainder to f)
abc4 = divmod(abc2, abc3[1])
e1 = abc3[1] * abc4[0]
e2 = abc4[1]
abc2 = e1 + e2
e3 = abc2 + (e1*-1) # This bit I am struggling
d = f
while (e % n) == 0 and (e % phiN) == 0:
for r in range(phiN, 0, -1):
e = r
while ((d * e) % phiN) != 1:
for r in range(1, 35):
e = r
print(p, q, n, phiN, e, d)
which lasted forever, and never ended. I even tried changing generate_primes (150) to generate_primes (10), but the same problem came up.
Does anyone have a solution since I would be happy to hear it (btw primesieve library is not automatically in python libraries, you have to download it yourself). Thank.
EDIT:
I did: while p == q: p = random.choice (choosing OffPrimes) but it’s hard for me to make a Euclidean rug