From 6dd022e6a0bd3c4c5eb73a709dfd0a2881270f71 Mon Sep 17 00:00:00 2001 From: Aldo Date: Wed, 28 Oct 2020 18:54:33 +0100 Subject: [PATCH] Python 3 fixes config.py alfcrypto.py --- DeDRM_plugin/alfcrypto.py | 12 ++++++------ DeDRM_plugin/config.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/DeDRM_plugin/alfcrypto.py b/DeDRM_plugin/alfcrypto.py index 4ce46e6..5c197a7 100644 --- a/DeDRM_plugin/alfcrypto.py +++ b/DeDRM_plugin/alfcrypto.py @@ -268,10 +268,10 @@ class KeyIVGen(object): # [c_char_p, c_ulong, c_char_p, c_ulong, c_ulong, c_ulong, c_char_p]) def pbkdf2(self, passwd, salt, iter, keylen): - def xorstr( a, b ): + def xorbytes( a, b ): if len(a) != len(b): - raise Exception("xorstr(): lengths differ") - return ''.join((chr(ord(x)^ord(y)) for x, y in zip(a, b))) + raise Exception("xorbytes(): lengths differ") + return bytes([x ^ y for x, y in zip(a, b)]) def prf( h, data ): hm = h.copy() @@ -283,17 +283,17 @@ class KeyIVGen(object): T = U for i in range(2, itercount+1): U = prf( h, U ) - T = xorstr( T, U ) + T = xorbytes( T, U ) return T sha = hashlib.sha1 digest_size = sha().digest_size # l - number of output blocks to produce - l = int(keylen / digest_size) + l = keylen // digest_size if keylen % digest_size != 0: l += 1 h = hmac.new( passwd, None, sha ) - T = "" + T = b"" for i in range(1, l+1): T += pbkdf2_F( h, salt, iter, i ) return T[0: keylen] diff --git a/DeDRM_plugin/config.py b/DeDRM_plugin/config.py index 3fb5baa..c319a6e 100644 --- a/DeDRM_plugin/config.py +++ b/DeDRM_plugin/config.py @@ -431,7 +431,7 @@ class ManageKeysDialog(QDialog): defaultname = "{0}.{1}".format(keyname, self.keyfile_ext) filename = choose_save_file(self, unique_dlg_name, caption, filters, all_files=False, initial_filename=defaultname) if filename: - with file(filename, 'wb') as fname: + with open(filename, 'w') as fname: if self.binary_file: fname.write(self.plugin_keys[keyname].decode('hex')) elif self.json_file: