Python:加快列表加密速度

标签 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, 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),并且是字符串和整数的组合。 有关如何加快该过程的任何提示。我还会考虑建议使用不同的加密。 谢谢!

最佳答案

密码的任何纯Python实现基本上都会很慢。 Python 的用途有很多,但快速位运算并不是其中之一。这就是为什么许多解释语言使用密码的 C/C++ 实现(甚至手动优化的汇编)。

尝试PyCrypto其中supports the AES-NI CPU instruction在最近的 Intel 和 AMD 处理器上。谁知道呢,您实际上可能会使用几分钟内无法被破解的密码实现(例如 key 大小为 56 位的单个 DES)。

关于Python:加快列表加密速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43733969/

相关文章:

python - 将评分函数从 sklearn.metrics 传递到 GridSearchCV

c# - 从特定索引中列出 AddRange?

encryption - 公钥加密中各种 key 有什么区别

python - 关于从 PyCharm 安装 SciPy

python - PyPDF2 : writing output to stdout fails with python3

python - python 中包含整数和字符串的列表

java - 将文件夹中的文件添加到 Android 应用程序的列表中

linux - 检查密码linux用户

algorithm - 使用逻辑门(XOR、NEG/NOT、NAND)的加密器/解密器

python - Pandas - 基于 bool DataFrame 替换 DataFrame 中的值