Fix kgenpids string vs bytes usage for python3 for calibre 5.1.
In order to properly get pids etc. we need to pass bytes to MD5 and SHA1 instead of unicode strings. Also ord() is no longer needed since data is bytes value gets int and we need chr() to get characters from the mapping bytearrays.
This commit is contained in:
parent
62e0a69089
commit
dca0cf7d00
|
@ -52,11 +52,11 @@ def SHA1(message):
|
||||||
def encode(data, map):
|
def encode(data, map):
|
||||||
result = ''
|
result = ''
|
||||||
for char in data:
|
for char in data:
|
||||||
value = ord(char)
|
value = char
|
||||||
Q = (value ^ 0x80) // len(map)
|
Q = (value ^ 0x80) // len(map)
|
||||||
R = value % len(map)
|
R = value % len(map)
|
||||||
result += map[Q]
|
result += chr(map[Q])
|
||||||
result += map[R]
|
result += chr(map[R])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# Hash the bytes in data and then encode the digest with the characters in map
|
# Hash the bytes in data and then encode the digest with the characters in map
|
||||||
|
@ -238,18 +238,18 @@ def getK4Pids(rec209, token, kindleDatabase):
|
||||||
# Get the UserName we added
|
# Get the UserName we added
|
||||||
UserName = bytearray.fromhex((kindleDatabase[1])['UserName']).decode()
|
UserName = bytearray.fromhex((kindleDatabase[1])['UserName']).decode()
|
||||||
# encode it
|
# encode it
|
||||||
encodedUsername = encodeHash(UserName,charMap1)
|
encodedUsername = encodeHash(UserName.encode(),charMap1)
|
||||||
#print "encodedUsername",encodedUsername.encode('hex')
|
#print "encodedUsername",encodedUsername.encode('hex')
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print("Keys not found in the database {0}.".format(kindleDatabase[0]))
|
print("Keys not found in the database {0}.".format(kindleDatabase[0]))
|
||||||
return pids
|
return pids
|
||||||
|
|
||||||
# Get the ID string used
|
# Get the ID string used
|
||||||
encodedIDString = encodeHash(IDString,charMap1)
|
encodedIDString = encodeHash(IDString.encode(),charMap1)
|
||||||
#print "encodedIDString",encodedIDString.encode('hex')
|
#print "encodedIDString",encodedIDString.encode('hex')
|
||||||
|
|
||||||
# concat, hash and encode to calculate the DSN
|
# concat, hash and encode to calculate the DSN
|
||||||
DSN = encode(SHA1(MazamaRandomNumber+encodedIDString+encodedUsername),charMap1)
|
DSN = encode(SHA1((MazamaRandomNumber+encodedIDString+encodedUsername).encode()),charMap1)
|
||||||
#print "DSN",DSN.encode('hex')
|
#print "DSN",DSN.encode('hex')
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue