crc

Calculate/validate bz2 (bzip2) CRC32 in Python

爷,独闯天下 提交于 2019-12-21 12:46:07
问题 I'm trying to calculate/validate the CRC32 checksums for compressed bzip2 archives. .magic:16 = 'BZ' signature/magic number .version:8 = 'h' for Bzip2 ('H'uffman coding) .hundred_k_blocksize:8 = '1'..'9' block-size 100 kB-900 kB .compressed_magic:48 = 0x314159265359 (BCD (pi)) .crc:32 = checksum for this block ... ... .eos_magic:48 = 0x177245385090 (BCD sqrt(pi)) .crc:32 = checksum for whole stream .padding:0..7 = align to whole byte http://en.wikipedia.org/wiki/Bzip2 So I know where the CRC

verilog实现CRC校验

佐手、 提交于 2019-12-20 04:17:55
1、模块代码; 2、用于GTKWave的测试代码。 module test(clk,rst_n,data,crc); input clk; input rst_n; input [7:0] data; output reg [15:0] crc=0; wire [23:0] stemp; reg [23:0] temp=0; parameter polynomial=17'b1_0001_0000_0010_0001; assign stemp={data,16'b0000_0000_0000_0000}; always@(posedge clk or negedge rst_n) begin if(!rst_n) begin crc<=0; temp<=stemp; end else begin if(temp[23]) temp[23:7]<=temp[23:7]^polynomial; else if(temp[22]) temp[22:6]<=temp[22:6]^polynomial; else if(temp[21]) temp[21:5]<=temp[21:5]^polynomial; else if(temp[20]) temp[20:4]<=temp[20:4]^polynomial; else if(temp[19]) temp[19:3]<=temp[19:3

CRC校验码(C#实现)

倖福魔咒の 提交于 2019-12-20 03:54:26
CRC校验(循环冗余校验)小知识 CRC即循环冗余校验码(Cyclic Redundancy Check):是数据通信领域中最常用的一种查错校验码,其特征是信息字段和校验字段的长度可以任意选定。循环冗余检查(CRC)是一种数据传输检错功能,对数据进行多项式计算,并将得到的结果附在帧的后面,接收设备也执行类似的算法,以保证数据传输的正确性和完整性。 适用规则: CRC-CCITT是一个17位生成多项式G=[1 0001 0000 0010 0001],用多项式形式表示为G(x)=x16+x12+x5+1,由它产生的检验码R的二进制位数是16位(2字节) using System ; using System . Collections . Generic ; using System . Linq ; using System . Threading . Tasks ; namespace MeterReading . API . App_Code { public class CRC16CCITT { private static readonly List < int > calcValus = new List < int > { 0x0000 , 0x1021 , 0x2042 , 0x3063 , 0x4084 , 0x50a5 , 0x60c6 , 0x70e7 ,

generating an safe hashcode for an objectgraph

旧巷老猫 提交于 2019-12-20 03:33:12
问题 I am importing some data from an file (xls, csv, xml) wich will result in a complex in-memory object graph. Now I need to know whether this graph has been modified since it once was exported. What would be a safe way to check this? I suppose I'd export a hashcode with the file? If so would the standard way of generating an object's hashcode suffice? How should I generate the hash? I would prefer to generate the hash on the object graph rather than on the actual stream/file. 回答1: You can

CRC校验程序设计

。_饼干妹妹 提交于 2019-12-19 09:18:39
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 程序的宗旨:通过编写CRC的校验程序,加深对CRC原理的理解,同时学会将书本上的原理运用于实际,动手实践才能学得更快。 注:本文关于CRC原理那部分内容,来自网络搜集。 1. 需求分析 编写一个CRC校验的模拟程序,该程序实现的功能如下: 输入:一串二进制比特串 输出:CRC校验码 2. CRC校验原理分析 在此,我们主要从适合于编程实现的角度分析CRC校验的算法原理,而不只是书本上关于CRC原理的介绍。 Cyclic Redundancy Check循环冗余检验,是基于数据计算一组效验码,用于核对数据传输过程中是否被更改或传输错误。 假设数据传输过程中需要发送15位的二进制信息g=101001110100001,这串二进制码可表示为代数多项式g(x) = x^14 + x^12 + x^9 + x^8 + x^7 + x^5 + 1,其中g中第k位的值,对应g(x)中x^k的系数。将g(x)乘以x^m,既将g后加m个0,然后除以m阶多项式h(x),得到的(m-1)阶余项r(x)对应的二进制码r就是CRC编码。 h(x)可以自由选择或者使用国际通行标准,一般按照h(x)的阶数m,将CRC算法称为CRC-m,比如CRC-8、CRC-32、CRC-64等。 g(x)和h(x)的除运算,可以通过g和h做xor(异或

Getting the CRC checksum of a byte array and adding it to that byte array

心不动则不痛 提交于 2019-12-18 15:48:38
问题 I have this byte array: static byte[] buf = new byte[] { (byte) 0x01, (byte) 0x04, (byte)0x00, (byte)0x01,(byte)0x00, (byte) 0x01}; Now, the CRC checksum of this byte array is supposed to be 0x60, 0x0A. I want the Java code to recreate this checksum, however I cant seem to recreate it. I have tried crc16: static int crc16(final byte[] buffer) { int crc = 0xFFFF; for (int j = 0; j < buffer.length ; j++) { crc = ((crc >>> 8) | (crc << 8) )& 0xffff; crc ^= (buffer[j] & 0xff);//byte to int, trunc

CRC16 checksum: HCS08 vs. Kermit vs. XMODEM

情到浓时终转凉″ 提交于 2019-12-18 12:36:25
问题 I'm trying to add CRC16 error detection to a Motorola HCS08 microcontroller application. My checksums don't match, though. One online CRC calculator provides both the result I see in my PC program and the result I see on the micro. It calls the micro's result "XModem" and the PC's result "Kermit." What is the difference between the way those two ancient protocols specify the use of CRC16? 回答1: you can implement 16 bit IBM, CCITT, XModem, Kermit, and CCITT 1D0F using the same basic code base.

how to generate 8bit crc in php [duplicate]

走远了吗. 提交于 2019-12-18 07:15:07
问题 This question already has answers here : Closed 6 years ago . 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; } 回答1: I've made a

CRC8-Check in PHP

百般思念 提交于 2019-12-17 20:59:02
问题 How can I generate a CRC-8 checksum in PHP? 回答1: function crcnifull ($dato, $byte) { static $PolyFull=0x8c; for ($i=0; $i<8; $i++) { $x=$byte&1; $byte>>=1; if ($dato&1) $byte|=0x80; if ($x) $byte^=$PolyFull; $dato>>=1; } return $byte; } function crc8 (array $ar,$n=false) { if ($n===false) $n=count($ar); $crcbyte=0; for ($i=0; $i<$n; $i++) $crcbyte=crcnifull($ar[$i], $crcbyte); return $crcbyte; } To use this function for a binary string you have to convert the binary string to an array first.

CRC32/CRC16算法C#中的实现

旧街凉风 提交于 2019-12-17 18:23:19
CRC32算法 1 using System; 2 using System.Collections.Generic; 3 using System.Text; 4 using System.IO; 5 6 namespace GetCRC32 7 { 8 class CRC32Cls 9 { 10 protected ulong[] Crc32Table; 11 //生成CRC32码表 12 public void GetCRC32Table() 13 { 14 ulong Crc; 15 Crc32Table = new ulong[256]; 16 int i,j; 17 for(i = 0;i < 256; i++) 18 { 19 Crc = (ulong)i; 20 for (j = 8; j > 0; j--) 21 { 22 if ((Crc & 1) == 1) 23 Crc = (Crc >> 1) ^ 0xEDB88320; 24 else 25 Crc >>= 1; 26 } 27 Crc32Table[i] = Crc; 28 } 29 } 30 31 //获取字符串的CRC32校验值 32 public ulong GetCRC32Str(string sInputString) 33 { 34 //生成码表 35 GetCRC32Table(); 36