-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecksum.py
21 lines (16 loc) · 6.51 KB
/
checksum.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from uint import Uint as FixedUint, Int as FixedInt
from binascii import unhexlify,hexlify
from struct import pack
def doChecksum(chunk):
v1 = FixedInt(0,32)
v2 = FixedInt(0,32)
for i, b in enumerate(chunk):
v2 = v2 + b
v1 = v1 + (i ^ b)
cs = (v1 * 0x10000) | (v2 & 0xFFFF)
return pack('l',cs)
test1 = unhexlify('04200000F600FE44BC000000400B00000A200000982AFC4D0C060000FC0B000009200000C200108B04030000081200000820000099044E073A0000000C15000008010100000001000200000046150000062000000200040E04040000481500000A01000000000600040000004C190000030101007003F807340000005019000009010000C800EC00100000008419000001100100410842081200000094190000011002003F08440812000000A619000001100400F803F1030A000000B8190000011005000008DD0712000000C219000001300000A300412284000000D4190000023000001A0056000C000000581A0000010149010A11527F38020000641A000001016001701FACA9200100009C1C000001014A010A11CC7D38020000BC1D000001012301EC07DC7A38020000F41F000001012401E90A717B380200002C22000001016801EB08FB76380200006424000001016901ED06FF77380200009C26000001016A01ED06577B38020000D428000001016B01ED06F77A380200000C2B000001016C01ED06977A38020000442D000001014801ED06AF7A380200007C2F000001014701ED060F7B38020000B431000001014601ED06877738020000EC33000001014501ED062F78380200002436000001014401EB08FB77380200005C38000001010101EC072C7A38020000943A000001012501DB18A57C38020000CC3C000001012601DB18AD7C38020000043F000001010201EE05CC78380200003C41000001010301EE05B278380200007443000001010401EE05247A38020000AC45000001012701DD162F8038020000E447000001012801100B467D380200001C4A000001010601EC07FE7738020000544C000001010701EC073A79380200008C4E000001010801EC073A7938020000C450000001010901EC07DE7838020000FC52000001010B01EB08AB7A380200003455000001010C01EB08A77A380200006C57000001010D01EB08AF7A38020000A459000001010E01EB08D97A38020000DC5B000001010F01EB08DB7A38020000145E000001011001EB08DD7A380200004C60000001012A01E50EDB77380200008462000001012B01F50D9B7738020000BC64000001012C01E50E797838020000F466000001012D01E50E0978380200002C69000002011010202B288F40020000646B000002012010142F288E40020000A46D0000020130101739898A40020000E46F000001010501EE05307A380200002472000002014010E33EC98C400200005C74000001011B01EE05047A380200009C760000020150104C415C8D40020000D4780000020160104313119040020000147B0000020170101505AB8A40020000547D0000020180100726B98E40020000947F000002019010A50AB38A40020000D481000001010A01FD0555793802000014840000020110209809A489400200004C860000020120203D0D678C400200008C88000001013301EE051C7A38020000CC8A000002014020C018409040020000048D000002015020AA11568640020000448F000001011601F80A427C380200008491000001011501E90A917A38020000BC93000001011401E90A2B7C38020000F49500000201002039093D8B400200002C980000020160201C16BA88400200006C9A000002017020E717F98740020000AC9C0000020180206718B18740020000EC9E0000020190209016F287400200002CA10000020100211D15598B400200006CA30000020110218921039340020000ACA5000002012021000B468B40020000ECA7000002013021311FC58D400200002CAA00000201402101177F8C400200006CAC0000020150216012EA8940020000ACAE0000020160218116BB8C40020000ECB00000020170215916938C400200002CB30000020180214C1C8C8E400200006CB5000002019021E2050A8A40020000ACB70000020100220704E98940020000ECB90000020185210318578A400200002CBC000001013401EE054C7A380200006CBE000001013501EE05CA7838020000A4C0000001013701EE05F07838020000DCC2000001014E01E310F5773802000014C5000001014F01E310FD77380200004CC7000001015101E90A8B773802000084C9000001015201E90A1B7838020000BCCB000001015301E90A277838020000F4CD000001015401E90AB777380200002CD00000010163011605FE773802000064D2000001016401EE05827A380200009CD4000001016501EE05467A38020000D4D6000001013F01EE05BE78380200000CD9000001014001EE056A7A3802000044DB000001014101EE053A7A380200007CDD0000052000000200040E04040000B4DF000002011022832CCBA040020000B8E30000032000000200166918300000F8E500000120000065F5CF2B0C48000010160100020120223D05EB8A400200001C5E01000201003039093D8B400200005C60010002011030800C5E8C400200009C62010002012030AF123B8E40020000DC64010002013030E219E08B400200001C670100020140307713B58F400200005C690100020150305610988E400200009C6B010002016030EF162B9040020000DC6D0100020170309D199F92400200001C700100020180309D111790400200005C720100020190309B0FCD8F400200009C740100020100311D31EF8D40020000DC76010002011031C91B958B400200001C790100020120319720958B400200005C7B0100020130316C221689400200009C7D010002014031C31B918D40020000DC7F0100020110400E0D048E400200001C82010002016031BE0B3A8D400200005C840100020170318D052B8B400200009C8601000201803182225A9040020000DC880100020190313D05EB8A400200001C8B0100020120404C1E0095400200005C8D010002013040C2162090400200009C8F010002014040921A729540020000DC910100020150405127CB96400200001C94010002016040DF1FF38D400200005C96010002017040EB28A98E400200009C98010002018040F839489A40020000DC9A010002012041D1238390400200001C9D0100020100410704E989400200005C9F010002011041F93AB199400200009CA101000201004039093D8B40020000DCA30100020110508C07BC8B400200001CA6010002012050F804CA88400200005CA8010002011000271B9D8C400200009CAA010002013050F304E58940020000DCAC0100020140506706B189400200001CAF010002015050AE055489400200005CB10100020160506C06B689400200009CB30100020170501B07058A40020000DCB501000201805089056B88400200001CB8010002019050B208968A400200005CBA0100020100514C284A87400200009CBC010002011051D332778F40020000DCBE010002012051CA3FFE9C400200001CC1010002013051E3208F8E400200005CC3010002014051761C6A90400200009CC5010002015051D8254A8840020000DCC70100020160517B30DB89400200001CCA0100020170518825CA87400200005CCC01000201805174288A87400200009CCE010002019051B208968A40020000DCD00100020100520704E989400200001CD3010002011052D52C7D93400200005CD50100020120522D1AFB89400200009CD701000201305253175B8C40020000DCD901000201255064077C8B400200001CDC01000201355064077C8B400200005CDE01000201455064077C8B400200009CE001000201555064077C8B40020000DCE201000201655064077C8B400200001CE501000201755064077C8B400200005CE701000201855064077C8B400200009CE9010002019019271B9D8C40020000DCEB01000201902933194B8C400200001CEE0100020190390F0BFD8A400200005CF0010002019049271B9D8C400200009CF201000201200039093D8B40020000DCF401000201005039093D8B400200001CF7010002010500E8235488400200005CF90100')
test2 = unhexlify('02300000CA000A010C0000002001000001300000A2004222840000002C01000004200000F600FE44BC000000B00100000A200000982AFC4D0C0600006C02000009200000C200108B04030000780800000820000099044E073A0000007C0B0000012000001BCA7B360C480000B60B0000080101000000010002000000C253000003200000B400887598700000C4530000062000000600082A040C00005CC400000A010000000006000400000060D00000030101005D04B5083400000064D0000002011000EE064433F004000098D000000201A000ED07C133F004000088D5000002010001EC083C34F004000078DA000009010000C800EC001000000068DF0000')
print(len(test1))
print(doChecksum(test1).hex())
print(doChecksum(test2).hex())