我一直在试图找到编码数字和解码数字。我知道你需要找到这些基本规则,并开始尝试创建一个python程序,它可以随机选择前150个素数来找到e变量和d变量。我这样做的方式是:RSA编码和解码[e,d]。在python中查找e和d ..更新
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)
历时永远运行,并没有完成运行。我甚至尝试将generate_primes(150)更改为generate_primes(10),但发生了同样的问题。
有没有人有解决方案,因为我会很高兴听到它(顺便说一句,primesieve库不会自动在Python库中,你必须自己下载它)。谢谢。
编辑:
我也做了: 而p ==问: P = random.choice(choiceOfPrimes) 但我有做的欧几里德垫的困难的时候
旁注:Python中的随机模块**不适合加密** – ppperry
那么,它在哪里卡住了? –