Calculating and validating nmea checksums

m's' for s' = s 1 # Let m'i = mi ^ E(K', i) for i = 1, 2, 3, ..., s # Let m's' = K' ^ h1 ^ h2 ^ ... s # # The one complication I add is that the last message block is hard # coded to the number of padbytes added, so that these can be stripped # during the undigest() step s = divmod(len(text), block_size)[0] blocks = [] hashes = [] for i in range(1, s 1): start = (i-1) * block_size end = start block_size mi = text[start:end] assert len(mi) == block_size cipherblock = mcipher.encrypt(long_to_bytes(i, block_size)) mticki = bytes_to_long(mi) ^ bytes_to_long(cipherblock) blocks.append(mticki) # calculate the hash block for this block hi = hcipher.encrypt(long_to_bytes(mticki ^ i, block_size)) hashes.append(bytes_to_long(hi)) # Add the padbytes length as a message block i = i 1 cipherblock = mcipher.encrypt(long_to_bytes(i, block_size)) mticki = padbytes ^ bytes_to_long(cipherblock) blocks.append(mticki) # calculate this block's hash hi = hcipher.encrypt(long_to_bytes(mticki ^ i, block_size)) hashes.append(bytes_to_long(hi)) # Now calculate the last message block of the sequence 1..s'.

$PTNL, GGK,172814.00,071296,3723.46587704, N,12202.26957864, W,3,06,1.7, EHT-6.777, M*48 $GPGGA,072840.20,5352.726971, N,00842.847935, E,0,00,1.0,00065.000, M,00000.000, M,0.00,*4D $HEHDT,226.2, T*2B $INGGA,120000.045,4928.46282, N,00008.01717, E,4,00,1.0,55.14, M,,,2.0,0001*34 $INGST,120000.045,,0.7,0.6,88.1,0.7,0.7,0.7*6C $INGSA, A,3,1,3,5,7,9,11,13,15,,,,,1.1,2.2,3.3 $INHDT,52.7, T*15 $GPGGA,104101.07,5149.695871, N,00443.244094, E,19,06,2,13.864, M,47.176, M,1.0,0001 $PDAS, QUAL,0.018,0.018,0.023,5 $GLL,0447.01472, S,01151.07695, E,05, D,9, ID1 $HCHDM,162.3, M*2F It is not advised to change the options if you do not understand the impact of the changes.

= 0xX" % (checksum, calculated_checksum)) handler = getattr(self, "handle_%s" % dispatch, None) decoder = getattr(self, "decode_%s" % dispatch, None) if not (dispatch and handler and decoder): # missing dispatch, handler, or decoder return # return handler(*decoder(*message)) try: decoded = decoder(*message) except Exception, e: raise Invalid Sentence("%r is not a valid %s (%s) sentence" % (line, sentencetype, dispatch)) return handler(*decoded) def pbkdf2(password, salt, iterations, dklen=0, digest=None): """ Implements PBKDF2 as defined in RFC 2898, section 5.2 HMAC SHA256 is used as the default pseudo random function.

Right now 10,000 iterations is the recommended default which takes 100ms on a 2.2Ghz Core 2 Duo.

""" # generate a random session key and K0, the key used to encrypt the # hash blocks. They are extracted from open source Python projects.You can click to vote up the examples you like, or click to vote down the exmaples you don't like.ms # random key K' (`key' in the code) # Compute output sequence: m'1, m'2, ...m's' for s' = s 1 # Let m'i = mi ^ E(K', i) for i = 1, 2, 3, ..., s # Let m's' = K' ^ h1 ^ h2 ^ ... s # # The one complication I add is that the last message block is hard # coded to the number of padbytes added, so that these can be stripped # during the undigest() step s = len(text) / block_size blocks = [] hashes = [] for i in range(1, s 1): start = (i-1) * block_size end = start block_size mi = text[start:end] assert len(mi) == block_size cipherblock = mcipher.encrypt(long_to_bytes(i, block_size)) mticki = bytes_to_long(mi) ^ bytes_to_long(cipherblock) blocks.append(mticki) # calculate the hash block for this block hi = hcipher.encrypt(long_to_bytes(mticki ^ i, block_size)) hashes.append(bytes_to_long(hi)) # Add the padbytes length as a message block i = i 1 cipherblock = mcipher.encrypt(long_to_bytes(i, block_size)) mticki = padbytes ^ bytes_to_long(cipherblock) blocks.append(mticki) # calculate this block's hash hi = hcipher.encrypt(long_to_bytes(mticki ^ i, block_size)) hashes.append(bytes_to_long(hi)) # Now calculate the last message block of the sequence 1..s'.

Leave a Reply