开发者

Checksum Explanation?

开发者 https://www.devze.com 2023-03-01 11:05 出处:网络
I am currently looking at checksums but am having开发者_如何学JAVA trouble fully understanding how they work.

I am currently looking at checksums but am having开发者_如何学JAVA trouble fully understanding how they work.

FYI, I have been looking at UDP checksums and Internet checksums. I have learned that UDP at the sender side performs 1s complement, however I am unclear as to what 1s complement is.

I have a rough idea of 1s complement being something to do with 'reversing' the values of all 1s and 0s, so that a 1 becomes a 0 and a 0 becomes a 1, but I do not know why this is done in the first place.

Could somebody kindly provide some information about checksums in general?

Thank you.


Checksum is mostly the hash (a one way encryption function) of some value to make sure that the data is consistent when it gets to the other end. The checksum is taken before the data is sent, then when the data is received at the other, the checksum of the same value is taken again, and matched with the checksum from the sender, if they are the same, then the data is in good state, else we know something is wrong.

Fairly simplified explanation.


A checksum is just an integer which is calculated by these rules: Sum everything in the packet except the checksum (I call it sum). Save in the checksum: -sum.

When the packet is arriving, sum everything that is in the packet. If the sum gives 0, then the packet is valid.

0

精彩评论

暂无评论...
验证码 换一张
取 消