【发布时间】:2015-07-18 06:17:14
【问题描述】:
我需要使用关键短语加密文件以用于部分评估。我在 python 中做我的并且遇到了问题。它是使用 python 2.7.4 编写的
我的代码如下:
导入数组
def encrypter(intext, shift, modder):
plain2 = list(intext)
plain = array.fromlist(plain2)
out = ''
j = 0
key = list(shift)
for c in plain:
if mod > 0:
x = chr((ord(c) + ord(key[(j % (len(plain) - 1)) % len(key)]) - 48) % 58 + 48)
if mod < 0:
x = chr((ord(c) - ord(key[(j % (len(plain) - 1)) % len(key)]) - 48) % 58 + 48)
out += x
j += 1
return out
sel = raw_input("Encrypt (e)/ Decrypt (d)")
if sel == 'e':
mod = 1
intext = open(raw_input("what is your file"),'r')
shift = raw_input("what is your first password")
encrypter(intext, shift, mod)
else:
pass
我的问题是,每当我使用名为 text1.txt 的文件运行此程序时,我都会收到此错误:
Traceback (most recent call last):
File "D:/Programming/Computing GCSE/Tasks/task3.py", line 22, in <module>
encrypter(intext, shift, mod)
File "D:/Programming/Computing GCSE/Tasks/task3.py", line 5, in encrypter
plain = array.fromlist(plain2)
AttributeError: 'module' object has no attribute 'fromlist'
任何人都可以建议更改我的代码吗?我需要这个相对较快,因为我的评估是在一个小时左右!
【问题讨论】:
-
如果这项工作很重要,您需要在它变得紧急之前尽早开始它。现在对你很紧急,而不是对我们。
标签: python arrays python-2.7 encryption