python的time模块没有clock,AttributeError:模块“时间”在Python 3.8中没有属性“时钟”...

I have written code to generate public and private keys. It works great at Python 3.7 but it fails in Python 3.8. I don't know how it fails in the latest version. Help me with some solutions.

Here's the Code:

from Crypto.PublicKey import RSA

def generate_keys():

modulus_length = 1024

key = RSA.generate(modulus_length)

pub_key = key.publickey()

private_key = key.exportKey()

public_key = pub_key.exportKey()

return private_key, public_key

a = generate_keys()

print(a)

Error in Python 3.8 version:

Traceback (most recent call last):

File "temp.py", line 18, in

a = generate_keys()

File "temp.py", line 8, in generate_keys

key = RSA.generate(modulus_length)

File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/PublicKey/RSA.py", line 508, in generate

obj = _RSA.generate_py(bits, rf, progress_func, e) # TODO: Don't use legacy _RSA module

File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/PublicKey/_RSA.py", line 50, in generate_py

p = pubkey.getStrongPrime(bits>>1, obj.e, 1e-12, randfunc)

File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Util/number.py", line 282, in getStrongPrime

X = getRandomRange (lower_bound, upper_bound, randfunc)

File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Util/number.py", line 123, in getRandomRange

value = getRandomInteger(bits, randfunc)

File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Util/number.py", line 104, in getRandomInteger

S = randfunc(N>>3)

File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 202, in read

return self._singleton.read(bytes)

File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 178, in read

return _UserFriendlyRNG.read(self, bytes)

File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 129, in read

self._ec.collect()

File "/home/paulsteven/.local/lib/python3.8/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 77, in collect

t = time.clock()

AttributeError: module 'time' has no attribute 'clock'

解决方案The function time.clock() has been removed, after having been deprecated since Python 3.3: use time.perf_counter() or time.process_time() instead, depending on your requirements, to have well-defined behavior. (Contributed by Matthias Bussonnier in bpo-36895.)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值