I need to encrypt a file with a key phrase for part of an assessment. I am doing mine in python and have run into a problem. It is written using python 2.7.4
My code is as follows:
import array
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
My problem is that whenever I run this with a file called text1.txt I get this error:
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'
Can anyone suggest a change in my code? I need this relatively quickly as my assessment is in an hour or so!