Calculating and validating nmea checksums

03-Jan-2018 14:25

Rivest calls this a fixed, publically-known encryption # key, but says nothing about the security implications of this key or # how to choose it.

key = self._inventkey(self.__key_size) K0 = self.__K0digit * self.__key_size # we need two cipher objects here, one that is used to encrypt the # message blocks and one that is used to encrypt the hashes.

checksum = lambda bytes: reduce(operator.xor, bytes, 0) checksums = list(map(checksum, segments)) return checksums def test_logical_operators(self): import operator def _check_bin_op(op): result = op(df1, df2) expected = Data Frame(op(df1.values, df2.values), index=df1.index, columns=df1.columns) self.assert_(result.values.dtype == np.bool_) assert_frame_equal(result, expected) def _check_unary_op(op): result = op(df1) expected = Data Frame(op(df1.values), index=df1.index, columns=df1.columns) self.assert_(result.values.dtype == np.bool_) assert_frame_equal(result, expected) df1 = df2 = df1 = Data Frame(df1) df2 = Data Frame(df2) _check_bin_op(operator.and_) _check_bin_op(operator.or_) _check_bin_op(operator.xor) _check_unary_op(operator.neg) def line Received(self, line): if not line.startswith('$'): if self.ignore_invalid_sentence: return raise Invalid Sentence("%r does not begin with $" % (line,)) # message is everything between $ and *, checksum is xor of all ASCII values of the message strmessage, checksum = line[1:].strip().split('*') message = strmessage.split(',') sentencetype, message = message[0], message[1:] dispatch = self.dispatch.get(sentencetype, None) if (not dispatch) and (not self.ignore_unknown_sentencetypes): raise Invalid Sentence("sentencetype %r" % (sentencetype,)) if not self.ignore_checksum_mismatch: checksum, calculated_checksum = int(checksum, 16), reduce(operator.xor, map(ord, strmessage)) if checksum !

= calculated_checksum: raise Invalid Checksum("Given 0xX !

return [long_to_bytes(i,self.__ciphermodule.block_size) for i in blocks] def digest(self, text): """digest(text:string) : [string] Perform the All-or-Nothing package transform on the given string.

block_size = self.__ciphermodule.block_size padbytes = block_size - (len(text) % block_size) text = text b(' ') * padbytes # Run through the algorithm: # s: number of message blocks (size of text / block_size) # input sequence: m1, m2, ...

return map(long_to_bytes, blocks) def digest(self, text): """digest(text:string) : [string] Perform the All-or-Nothing package transform on the given string.

Output is a list of message blocks describing the transformed text, where each block is a string of bit length equal to the ciphermodule's block_size.

calculating and validating nmea checksums-14calculating and validating nmea checksums-73calculating and validating nmea checksums-59

mcipher = self.__newcipher(key) hcipher = self.__newcipher(K0) # Pad the text so that its length is a multiple of the cipher's # block_size.seg_size = length // target segments = [bytes[i * seg_size:(i 1) * seg_size] for i in range(target)] # Catch any left-over bytes in the last segment.segments[-1].extend(bytes[target * seg_size:]) # Use a simple XOR checksum-like function for compression.Your votes will be used in our system to extract more high-quality examples.You may also check out all available functions/classes of the module length: raise Value Error("Fewer input bytes than requested output") # Split `bytes` into `target` segments.

mcipher = self.__newcipher(key) hcipher = self.__newcipher(K0) # Pad the text so that its length is a multiple of the cipher's # block_size.

seg_size = length // target segments = [bytes[i * seg_size:(i 1) * seg_size] for i in range(target)] # Catch any left-over bytes in the last segment.

segments[-1].extend(bytes[target * seg_size:]) # Use a simple XOR checksum-like function for compression.

Your votes will be used in our system to extract more high-quality examples.

You may also check out all available functions/classes of the module length: raise Value Error("Fewer input bytes than requested output") # Split `bytes` into `target` segments.

This # will contain the random session key XOR'd with all the hash blocks, # so that for undigest(), once all the hash blocks are calculated, the # session key can be trivially extracted.