crc16 | Implements the 16-bit cyclic redundancy check or CRC-16
kandi X-RAY | crc16 Summary
kandi X-RAY | crc16 Summary
A Go package implementing the 16-bit Cyclic Redundancy Check, or CRC-16, checksum.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- makeBitsReversedTable returns a Table constructed from a Table .
- makeTable creates a new Table .
- tableSum returns the checksum of the table .
- update returns the hash of p .
- Update updates p with crc .
- appendUint16 appends a uint16 to b .
- updateNoXOR updates the checksum of p .
- updateBitsReversed calculates the checksum of p .
- MakeTableNoXOR creates a table with XOR .
- readUint16 reads a uint16 from b .
crc16 Key Features
crc16 Examples and Code Snippets
Community Discussions
Trending Discussions on crc16
QUESTION
I want to check if the content of a file changed. My plan if to add a hash in the last line of the file.
Later on, I can read the file, hash it (hash everything except the last line) and compare it to the last line of the file (initial hash).
I cannot use the last modified date/time. I need to use a hash or any kind of coding stored inside the file. I use C# to code the app. What is the most reasoneble/easiest way of doing this? I don't know which of the the following would be a good match for me: Sha1,2,3 - crc16/32/64 - md5? I do not need the method to be quick or secure.
Thank you!
...ANSWER
Answered 2022-Mar-11 at 13:39What are you trying to protect yourself against?
Accidental change? Then your approach sounds fine. (Make sure to add handling for when the last line with the hash was deleted by accident too.)
Malicious change? Then you'd need to hash the file content plus some private key, and use a secure hashing algorithm. MD5 is good for accidental changes because it is fast, but cryptographically it is considered broken.
QUESTION
ANSWER
Answered 2022-Jan-21 at 10:50Your input data is wrong. The first one should be b'\x01\x04\x00\x0b\x00\x01'
for example. The first string as written by you has '\0'
(a null character), followed by the literal characters 'x04'
, and so on. You can check this by printing the strings.
Once this is corrected your code appears to give the correct results.
As a minor note, your type information for the data
parameter says it takes a bytearray
but you're actually passing it bytes
.
QUESTION
I have some trouble implementing a CRC16 for can message, I followed the instructions given by this website https://barrgroup.com/embedded-systems/how-to/crc-calculation-c-code and http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html#ch5, plus other implention I have seen in here ( for example Function to Calculate a CRC16 Checksum).
I don't understand how it is processed.
My message here is in form of bytes, for example char message[4] = {0x12, 0x34, 0x56, 0x78}
. When I go through the first loop I just take the first byte, shift it by 8 and calculate the remainder
with a POLYNOME
of 16 bits
.
That means we have 0x1200
and we go through the second loop with it, which mean I do a XOR
with the POLYNOME
that I store in the remainder
but I don't quite understand why this works, especially when I look at this code, the 2nd
, 3rd
and 4th
bytes
of my message which should get XORed
by the 8 first bits
of the POLYNOME
at some points aren't going through it at all.
According to the wikipedia explanation https://en.wikipedia.org/wiki/Cyclic_redundancy_check the polynome goes through the whole message at once and not byte by byte.
I don't know how that translates to doing the CRC of 0x12345678
byte by byte.
ANSWER
Answered 2021-Dec-14 at 20:36I don't understand how it is processed.
Maybe it will help to describe the bit by bit operations for 8 bits of data:
QUESTION
I am trying to calculate CRC for the first time. I have read a few pages that explain what is crc and how to calculate. Mainly this : https://www.fatalerrors.org/a/implementation-of-crc-checksum-c-crc16-as-an-example.html
I have a code that calculates CRC16
...ANSWER
Answered 2021-Dec-09 at 13:17You are missing a bit shift in the calculation. Change:
QUESTION
Please excuse me if the question will be simple, I'm kinda new with CRC.
I've got cpp CRC16 func with defined crc table and I want exactly the same results in python. I used some libraries, but all of them gave me different results. The reason is probably with diference in crc tables, but all the algorithms that I found don't have defined tables that I can swap with mine.
Original func:
...ANSWER
Answered 2021-Nov-19 at 20:16The parameters and name of that CRC (click on link for more information):
QUESTION
I am in need of a highly optimized CRC8 algorithm. My goal is to develop a Slice-by-4 solution as known from CRC16 / CRC32. I want to keep the code as close to the solution which I am using for CRC16 posted below.
Functions to generate the CRC LookUp-Table:
...ANSWER
Answered 2021-Nov-07 at 00:07You didn't provide your polynomial, initial value, or final exclusive or. With those (and that the CRC in your case is not reflected), you can use crcany to generate the code for you.
Here is an example for little-endian slice-by-4:
QUESTION
I'm struggling with an old radiation sensor and his communication protocol.
The sensor is event driven, the master starts the communication with a data transmission or a data request.
Each data telegram uses a CRC16 to check only the variable data block and a CRC8 to check all the telegram.
My main problem is the crc16, According to the datasheet the poly used to check the data block is:
CRC16 = X^14 + X^12 + X^5 + 1
--> 0x5021 ??
I captured some data with a valid CRC16 and tried to replicate the expected value in order to send my own data transmission, but I can't get the same value.
I'm using the sunshine CRC calculator trying any possible combination with that poly.
I also try CRC Reveng but no results.
Here are a few data with the correct CRC16:.
ANSWER
Answered 2021-Nov-04 at 16:08Looks like a typo on the polynomial. An n-bit CRC polynomial always starts with xn. Like your correct 8-bit polynomial. The 16-bit polynomial should read X16 + X12 + X5 + 1, which in fact is a very common 16-bit CRC polynomial.
To preserve the note in the comment, the four data bytes in the examples are swapped in each pair of bytes, which needs to be undone to get the correct CRC. (The control bytes in the CRC8 example are not swapped.)
So 14 00 00 0a
becomes 00 14 0a 00
, for which the above-described CRC gives the expected 0x1b84
.
I would guess that the CRC is stored in the stream also swapped, so the message as bytes would be 00 14 0a 00 84 1b
. That results in a sequence whose total CRC is 0.
QUESTION
I need to calculate a CRC16 for hex codes like this one:
08010000016B40D8EA30010000000000000000000000000000000105021503010101425E0F01F10000601A014E000000000000000001
The expected result for the above hex String is 0000C7CF
( 51151 )
I have this working JavaScript implementation for that, which I am trying to translate to Java:
...ANSWER
Answered 2021-Oct-19 at 10:22Change the following line from
crc ^= b
to
crc ^= (b & 0xff)
In java, byte
ranges from -128 to 127, so you have to make it unsigned.
QUESTION
I have created a minimal stereo FLAC file according to the specifications here. It is a single block of 8192 samples of 0 encoded as a constant:
...ANSWER
Answered 2021-Sep-08 at 12:19While the left, right and mid channels are 16 bit, the side channel needs to be 17 bit, because otherwise the side channel could clip or overflow.
For example, if at a certain point in the stream, the left channel is 32767 (the maximum positive integer when using signed 16-bit) and the right channel is -32768 (the maximum negative integer) the result when using left-side would be a side sample of -65535, which has to be stored with at least 17 bit.
I agree that this is something not mentioned clearly in the FLAC specification. See also this code on github.
QUESTION
Below code is from crc32 function reference in PHP website for CRC16-CCITT calculation. This works for ASCII input data. How can I make it work for HEX input data? What do I need to change? Thank you for your help.
...ANSWER
Answered 2021-Aug-13 at 20:09You would need to first convert the hexadecimal string into a string of bytes with hexdec
and chr
on each pair of hexadecimal digits, and concatenating those into a string.
For your example, you can provide the string of three bytes directly as "\x7f\x01\x00"
.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install crc16
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page