crc

compute crc of file in python

故事扮演 提交于 2019-11-30 03:43:52
I want to calculate the CRC of file and get output like: E45A12AC . Here's my code: #!/usr/bin/env python import os, sys import zlib def crc(fileName): fd = open(fileName,"rb") content = fd.readlines() fd.close() for eachLine in content: zlib.crc32(eachLine) for eachFile in sys.argv[1:]: crc(eachFile) This calculates the CRC for each line, but its output (e.g. -1767935985 ) is not what I want. Hashlib works the way I want, but it computes the md5: import hashlib m = hashlib.md5() for line in open('data.txt', 'rb'): m.update(line) print m.hexdigest() Is it possible to get something similar

What checksum algorithm should I use?

北城余情 提交于 2019-11-29 20:34:18
I'm building a system which needs to be able to find if blobs of bytes have been updated . Rather than storing the whole blob (they can be up to 5MBs), I'm thinking I should compute a checksum of it, store this and compute the same checksum a little bit later, to see whether the blog has been updated. The goal is to minimize the following (in that order) : size of the checksum time to compute likeliness of collisions (2 identical checksums happening even if the content has been modified). It is acceptable for our system to have collision not more than 1/1,000,000. The concern is not security,

Java compatible cksum function

♀尐吖头ヾ 提交于 2019-11-29 19:57:33
问题 Is there any library/code in Java to calculate the 32-bit CRC of a stream of bytes in a way thats consistent with the cksum command in unix ? 回答1: Jacksum: http://www.jonelo.de/java/jacksum/index.html cksum algorithm: POSIX 1003.2 CRC algorithm length: 32 bits type: crc since: Jacksum 1.0.0 comment: - under BeOS it is /bin/cksum - under FreeBSD it is /usr/bin/cksum - under HP-UX it is /usr/bin/cksum and /usr/bin/sum -p - under IBM AIX it is /usr/bin/cksum - under Linux it is /usr/bin/cksum It

CRC32校验算法-C实现

a 夏天 提交于 2019-11-29 16:02:47
CRC即循环冗余校验码 CRC即循环冗余校验码(Cyclic Redundancy Check):是数据通信领域中最常用的一种差错校验码,其特征是信息字段和校验字段的长度可以任意选定。 CRC校验实用程序库在数据存储和数据通讯领域,为了保证数据的正确,就不得不采用检错的手段。 以下是CRC32的C语言实现,经过测试,能够正确运行: https://blog.csdn.net/weed_hz/article/details/25132343 来源: https://blog.csdn.net/qq_23940143/article/details/100850069

CRC16 ISO 13239 Implementation

Deadly 提交于 2019-11-29 14:59:47
问题 i'm trying to implement Crc16 in C#. I already tried many different implementations, but most of them gives me different values. Here are some of the codes that i already used. private static int POLYNOMIAL = 0x8408; private static int PRESET_VALUE = 0xFFFF; public static int crc16(byte[] data) { int current_crc_value = PRESET_VALUE; for (int i = 0; i < data.Length; i++) { current_crc_value ^= data[i] & 0xFF; for (int j = 0; j < 8; j++) { if ((current_crc_value & 1) != 0) { current_crc_value

java编写的两个modbus CRC16实现

纵然是瞬间 提交于 2019-11-29 13:08:06
在使用java与下位机通信中,经常会涉及到modbus协议,而作为校验手段,CRC16必不可少。 网上搜到的绝大部分实现都不是为modbus编写的,经过与下位机的通信检验,我选择了其中两个比较简洁的实现并根据自己的需要加以改进,完成了以下两个工具类。 希望对需要此类编程的朋友有所帮助。 对附件说明如下: class CRC_16 ——采用运算实现的CRC class CRC16M——采用查表实现的CRC 对主要方法说明如下: alex_crc16——crc运算 getSendBuf——根据十六进制字符串获得带CRC校验字的字节数组 getBufHexStr——将字节数组打印为十六进制字符串 checkBuf——验证应答的字节数组 另外今天调程序还犯了一个低级错误, 因为java中的byte是无符号的,因此在多数情况下是不能直接拿来相加的,需要先转换为无符号值 。 例如:说明书算式为: (bh & 03H) * 256 + bl ,即高字节后两位乘256加上低字节,如果直接将低字节拿去相加可能造成低字节值为负数。 加之前必须进行类似这样的转换 (bh&0x03)*256+(int)(bl&0xff) 转载于:https://my.oschina.net/u/1440018/blog/543233 来源: https://blog.csdn.net/chunning1112

how to generate 8bit crc in php [duplicate]

Deadly 提交于 2019-11-29 12:11:40
Possible Duplicate: CRC8-Check in PHP Is there any good PHP 8bit CRC generation? I searched and I couldn't find any good source. I've found a 16bit though: function crc16($string) { $crc = 0xFFFF; for ($x = 0; $x < strlen ($string); $x++) { $crc = $crc ^ ord($string[$x]); for ($y = 0; $y < 8; $y++) { if (($crc & 0x0001) == 0x0001) { $crc = (($crc >> 1) ^ 0xA001); } else { $crc = $crc >> 1; } } } return $crc; } HabibS I've made a simple code based on Mark's code in c, and will put it here for anyone to use: global $crc8_table; $crc8_table = array( 0x00, 0x3e, 0x7c, 0x42, 0xf8, 0xc6, 0x84, 0xba,

How to configure calculation of CRC table

China☆狼群 提交于 2019-11-29 05:09:58
There are a lot of CRC calculation examples out there. Simple implementations with bit shifting and more efficient with a pre-calculated table. But there are also a lot of Parameters of a CRC beside the polynomial that affect the calculation. You can evaluate these parameters here: http://zorc.breitbandkatze.de/crc.html These parameters are initial value of CRC reflection of input data reflection of output data final XOR value for CRC For some "standard" CRC algorithm these parameters are well defined, like CRC-16 (CCITT). But there are some implementations that use different parameters. My

Data Length vs CRC Length

青春壹個敷衍的年華 提交于 2019-11-28 22:32:15
I've seen 8-bit, 16-bit, and 32-bit CRCs. At what point do I need to jump to a wider CRC? My gut reaction is that it is based on the data length: 1-100 bytes: 8-bit CRC 101 - 1000 bytes: 16-bit CRC 1001 - ??? bytes: 32-bit CRC EDIT: Looking at the Wikipedia page about CRC and Lott's answer, here' what we have: <64 bytes: 8-bit CRC <16K bytes: 16-bit CRC <512M bytes: 32-bit CRC It's not a research topic. It's really well understood: http://en.wikipedia.org/wiki/Cyclic_redundancy_check The math is pretty simple. An 8-bit CRC boils all messages down to one of 256 values. If your message is more

What checksum algorithm should I use?

余生长醉 提交于 2019-11-28 16:36:51
问题 I'm building a system which needs to be able to find if blobs of bytes have been updated . Rather than storing the whole blob (they can be up to 5MBs), I'm thinking I should compute a checksum of it, store this and compute the same checksum a little bit later, to see whether the blog has been updated. The goal is to minimize the following (in that order) : size of the checksum time to compute likeliness of collisions (2 identical checksums happening even if the content has been modified). It