Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:加速列表的加密_Python_List_Encryption - Fatal编程技术网

Python:加速列表的加密

Python:加速列表的加密,python,list,encryption,Python,List,Encryption,我正在使用python加密字符串列表。然而,它需要很长的时间(0.045秒/列表)。我是否犯了任何使我的代码运行缓慢的大错误。 代码如下: row=['string1', 'string2','string3','string4','string5','string6','string7','string8','string9'] from pyDes import * import time def encode(data,password): k = des(password,

我正在使用python加密字符串列表。然而,它需要很长的时间(0.045秒/列表)。我是否犯了任何使我的代码运行缓慢的大错误。 代码如下:

row=['string1', 'string2','string3','string4','string5','string6','string7','string8','string9']

from pyDes import *
import time

def encode(data,password):
    k = des(password, CBC, "\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5)
    d = k.encrypt(data)
    return d

start=time.time()
for idx, val in enumerate(row):
    row[idx]=encode(str(val).encode(), 'password')

end=time.time()    
print(end-start)
实际上,该列表要长得多(~33),是字符串和整数的组合。 关于如何加快流程的任何提示。我也会考虑使用DFFRONT加密。
谢谢大家!

密码的任何纯python实现基本上都是缓慢的。Python是为许多事情而设计的,但快速位操作不是其中之一。这就是为什么许多解释语言使用密码的C/C++实现(甚至手动优化的汇编)


在最新的英特尔和AMD处理器上试一试。谁知道呢,您可能实际上使用了一种密码实现,它在几分钟内无法被破解(比如密钥大小为56位的单DES)。

您是否尝试过
row=list(map(encode,row))
?话虽如此,您使用的编码将承担大部分计算时间,因此,出于某些不起作用的原因,即使我在encode函数中硬编码密码,也只需对其进行优化即可。我在尝试创建map对象的列表时出错。Ofc。。是的,很抱歉。您可以解决此问题(使用
functools
中的
partial
),但这不会产生太大影响。专注于加密,但我不能就此提出任何建议。由于Python的bignum功能构建在核心语言中,因此Python对于非对称原语来说非常容易。没有一种语言更容易进行RSA计算的实验。我尝试了PyCrypto,但由于某种原因,我无法进行解密(不知道为什么)。但感谢您的投入,至少现在我知道python并不是完成这项任务的最佳方式。