crc

How could I guess a checksum algorithm?

我怕爱的太早我们不能终老 提交于 2019-12-17 15:58:08
问题 Let's assume that I have some packets with a 16-bit checksum at the end. I would like to guess which checksum algorithm is used. For a start, from dump data I can see that one byte change in the packet's payload totally changes the checksum, so I can assume that it isn't some kind of simple XOR or sum. Then I tried several variations of CRC16, but without much luck. This question might be more biased towards cryptography, but I'm really interested in any easy to understand statistical tools

Get CRC checksum of an NSData in Objective-C

妖精的绣舞 提交于 2019-12-17 15:44:47
问题 How can I count CRC (32 or 64) of an NSData object in Objective-C? Thanks in advance! 回答1: Have a look here for a CRC32 for NSData http://classroomm.com/objective-c/index.php?action=printpage;topic=2891.0 回答2: Use crc32() function from zlib library: #import <zlib.h> NSData *data; // ... unsigned long result = crc32(0, data.bytes, data.length); NSLog(@"CRC32: %lu", result); Make sure to link libz library with your project: 回答3: From iOS11 use this: unsigned long result = crc32_z(0, data.bytes,

Function to Calculate a CRC16 Checksum

柔情痞子 提交于 2019-12-17 15:26:48
问题 I'm working on a library to provide simple reliable communication over an RS232 or RS485 connection. Part of this code involves using a CRC16 checksum on the data to detect corruption from line noise. I've created a function to calculate a CRC16 checksum, but it doesn't seem to be outputting correct values. The relevant code I've written is below (it can also be found here). #include <stdint.h> #define CRC16 0x8005 uint16_t gen_crc16(const uint8_t *data, uint16_t size) { uint16_t out = 0; int

how to calculate ANSI CRC16 polynomial (0x8005) in python3?

跟風遠走 提交于 2019-12-13 16:22:06
问题 I tried to calculate ANSI CRC16 polynomial (0x8005) using this code import crcmod crc16 = crcmod.mkCrcFun(0x8005, 0xffff, True) but I got this error message ValueError: The degree of the polynomial must be 8, 16, 24, 32 or 64 回答1: There is an implied 1 at the beginning of 0x8005 crcmod expects you to provide the 1 explicitly import crcmod crc16 = crcmod.mkCrcFun(0x18005, 0xffff, True) 来源: https://stackoverflow.com/questions/24851027/how-to-calculate-ansi-crc16-polynomial-0x8005-in-python3

CRC calculation in Java

别来无恙 提交于 2019-12-13 15:22:29
问题 I'm reading a file from serialport using x-modem protocol and 133 bytes packet. I'm reading in that 1 byte is SOH 2 byte packet number 3 byte nagative of packet number next 128 bytes data 2 bytes CRC sent from other side. I have to calculate CRC of 128 bytes data and 2 bytes crc sent from other side that I have to make it single byte and have to comapare with my calculated crc. How can I do this in java? 回答1: Try using Jacksum. 回答2: Sun JDK 1.6 contains sun.misc.CRC16, but there is a

crc64

谁都会走 提交于 2019-12-13 01:13:08
oss2\models.py /*--> */ /*--> */ class PartInfo( object ): """ 表示分片信息的文件。 该文件既用于 :func:`list_parts <oss2.Bucket.list_parts>` 的输出,也用于 :func:`complete_multipart_upload <oss2.Bucket.complete_multipart_upload>` 的输入。 :param int part_number: 分片号 :param str etag: 分片的 ETag :param int size: 分片的大小。用在 `list_parts` 的结果里,也用与分片对象做 crc combine 得到整个对象 crc64 值 :param int last_modified: 该分片最后修改的时间戳,类型为 int 。参考 :ref:`unix_time` :param int part_crc: 该分片的 crc64 值 """ def __init__ ( self , part_number , etag , size= None, last_modified= None, part_crc= None ): self .part_number = part_number self .etag = etag self

CRC检验码计算——C语言(CRC8/16/32)

自闭症网瘾萝莉.ら 提交于 2019-12-12 13:52:47
1、基本概念 1.1、循环冗余检测(Cyclic Redundancy Check,CRC) CRC编码也被称为多项式编码(polynomial code),因为该编码能够将要发送的比特串看作是系数为 0 和 1 的一个多项式。对比特串操作被解释为多项式算术。 1.2、CRC参数 D:D数据拥有 d 比特 G:发送方和接收方需要协商一个 r+1 比特模式,称为生成多项式(G), G 的最高有效位比特(最高位)和 最低有效位比特(最低位)必须为 1 R:发送方选择 r 个附加比特,称为 R(CRC校验码) (1) 计算 :R 是数据 D 通过 模 2 除法 除 G 运算得到的(姑且这么说)余数, 这个 R 就是 FCS(检测帧序列) ,发送时把 R 附加到数据 D 后面。 (2) 检验 :一共接收有 d+r 个比特,用模 2 算术恰好能够被 G 整除(没有余数),即 (D+R)/ G,如果余数为 0,接收方认为数据正确而被接收,否则接收方知道出现了差错。 1.3、CRC原理解释 所有 CRC 计算采用模 2 算术,即在加法中不进位,在减法中不借位,意味加法和减法是相同的, 等价于操作数的按位异或(XOR)运算 ,而不是需要借位运算。 例如: D = 10110011,d = 8 G = 11001,r = 4 通过计算得到 R = 0100 在这种情况下传输 12 个比特是

What is the inverse of crc32_combine()'s matrix trick?

落爺英雄遲暮 提交于 2019-12-12 08:14:19
问题 zlib's crc32_combine() takes crcA, crcB, and lengthB to calculate crcAB. # returns crcAB crc32_combine(crcA, crcB, lenB) Using concepts from Mark Adler's awesome posts here and here I was able to produce crc32_trim_trailing.pl which takes crcAB, crcB, and lengthB to calculate crcA (I use this to peel off padding of a known length and value). # prints crcA perl crc32_trim_trailing.pl $crcAB $crcB $lenB Unfortunately, this uses the principles of the slow method described, where each null byte

Calculating CRC initial value instead of appending the CRC to payload

半城伤御伤魂 提交于 2019-12-12 03:13:56
问题 Most of the CRCs I've implemented were appending the calculated CRC value to the message (payload) and checking for a zero result at the receiver after all bytes incl. CRC value were fed through the CRC register. Obviously this is a quite standard approach. Now I would like to use a different approach: Calculate a value from the payload. Use that value as initial value for the CRC register before the message bytes (payload) are fed through the CRC register such that the result after the last

CRC-16 (IBM) Reverse Lookup in C++

断了今生、忘了曾经 提交于 2019-12-12 02:04:57
问题 I'm having trouble with creating a Maxim CRC-16 Algorithm that would match a specific output. I've listed the resources I've used to help me write the program below: Maxim App Note 27 Sanity-Free CRC-16 Computation Julia CRC Computation (By Andrew Cooke) CRC-16 Lookup Table (in C) Another CRC Lookup Table in C CRC Wiki Page With the above references, I wrote a simple program that would compute the CRC-16 using both a bit by bit approach, and a look-up table approach. The bit-by-bit approach