我已经在python中完成了一个项目。它是我使用EC ElGamal算法进行加密和解密的椭圆曲线密码学加密解密系统。绘制曲线上的点,如以下代码所示:
def prepare_curve_parameters(self):
len_password = len(self.password)
self.prime_nums = get_nPrimeNumbers(127 + len_password)
P = self.prime_nums[-1]
D = self.prime_nums[len_password]
password_block = [ord(x) for x in self.password]
if len_password % 2 != 0:
password_block.append(len_password)
print ('password ascii', password_block)
half_len = len(password_block) / 2
block1 = password_block[:half_len]
block2 = password_block[half_len:]
print('password block 1', block1)
print('password block 2', block2)
byte_array1 = array.array('B', block1)
M = zlib.crc32(byte_array1) & 0xffffffff
byte_array2 = array.array('B', block2)
N = zlib.crc32(byte_array2) & 0xffffffff
print("M={}, N={}".format(M, N))
A = M % P
B = N % P
print("Curve [A={}, B={}, P={}]".format(A, B, P))
self.a = A
self.b = B
self.p = P
self.d = D
def get_cryptosystem(self):
self.prepare_curve_parameters()
ec = EC(self.a, self.b, self.p)
rand_perf_square = get_randomPerfSquare(self.p)
g, _ = ec.at(rand_perf_square)
print('g', g)
self.eg = ElGamal(ec, g)
问题是,在大多数情况下,每当我输入密码时,密码都无法使用,并显示以下错误。
Traceback (most recent call last):
File "CryptoSystem.py", line 144, in <module>
main()
File "CryptoSystem.py", line 140, in main
decrypt(im_file, password, dec_file)
File "CryptoSystem.py", line 114, in decrypt
img_str, status = crypto.decrypt(enc_file)
File "CryptoSystem.py", line 82, in decrypt
cipher = pickle.load(open(im_file, 'rb'))
File "/usr/lib/python2.7/pickle.py", line 1384, in load
return Unpickler(file).load()
File "/usr/lib/python2.7/pickle.py", line 864, in load
dispatch[key](self)
File "/usr/lib/python2.7/pickle.py", line 897, in load_persid
self.append(self.persistent_load(pid))
AttributeError: Unpickler instance has no attribute 'persistent_load'