2
0
mirror of https://github.com/apprenticeharper/DeDRM_tools synced 2024-11-18 21:25:39 +00:00
DeDRM_tools/Kindle_Mobi_Tools/PIDCheck.py
Apprentice Alf bf03edd18c tools v2.0
Most tools now have plugins
2015-03-03 18:02:10 +00:00

41 lines
939 B
Python

#!/usr/bin/python
#
# This is a python script. You need a Python interpreter to run it.
# For example, ActiveState Python, which exists for windows.
#
# Changelog
# 1.00 - Initial version
__version__ = '1.00'
import sys
import struct
import binascii
def checksumPid(s):
letters = "ABCDEFGHIJKLMNPQRSTUVWXYZ123456789"
crc = (~binascii.crc32(s,-1))&0xFFFFFFFF
crc = crc ^ (crc >> 16)
res = s
l = len(letters)
for i in (0,1):
b = crc & 0xff
pos = (b // l) ^ (b % l)
res += letters[pos%l]
crc >>= 8
return res
if __name__ == "__main__":
if len(sys.argv) != 2:
print "Checks Mobipocket PID checksum"
print "Usage:"
print " %s <PID>" % sys.argv[0]
sys.exit(1)
else:
pid = sys.argv[1]
if len(pid) == 8:
pid = checksumPid(pid)
else:
pid = checksumPid(pid[:8])
print pid
sys.exit(0)