Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

背包加密中makeKey函数的问题 #540

Open
fztfztfztfzt opened this issue May 5, 2019 · 1 comment
Open

背包加密中makeKey函数的问题 #540

fztfztfztfzt opened this issue May 5, 2019 · 1 comment

Comments

@fztfztfztfzt
Copy link
Contributor

背包加密中Archaic题目中的makeKey函数,原题中是

def makeKey(n):
    privKey = [random.randint(1, 4**n)]
    s = privKey[0]
    for i in range(1, n):
        privKey.append(random.randint(s + 1, 4**(n + i)))
        s += privKey[i]
    q = random.randint(privKey[n-1] + 1, 2*privKey[n-1])
    r = random.randint(1, q)
    while gmpy2.gcd(r, q) != 1:
        r = random.randint(1, q)
    pubKey = [ r*w % q for w in privKey ]
    return privKey, q, r, pubKey

其中q应该是q = random.randint(s+ 1, 2*s)吧,能解出来是因为正好最后一位是0?

@iromise
Copy link
Member

iromise commented May 5, 2019

好像是这么回事,我有时间仔细看一下如何修改一下,目前时间不太充足。当然欢迎直接提供 PR。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants