Docsity

CRC Mathematics-Data Communication-Lecture Handouts, Lecture notes of Data Communication Systems and Computer Networks

Toggle sidebar
bg1
๎˜ƒ
CRCโ€Mathematics๎˜ƒ
CRC๎˜ƒ๎˜ƒ
Take๎˜ƒa๎˜ƒbinary๎˜ƒmessage๎˜ƒand๎˜ƒconvert๎˜ƒit๎˜ƒto๎˜ƒa๎˜ƒpolynomial๎˜ƒthen๎˜ƒdivide๎˜ƒit๎˜ƒby๎˜ƒanother๎˜ƒpredefined๎˜ƒ
polynomial๎˜ƒcalled๎˜ƒthe๎˜ƒkey.๎˜ƒThe๎˜ƒremainder๎˜ƒfrom๎˜ƒthis๎˜ƒdivision๎˜ƒis๎˜ƒthe๎˜ƒCRC.๎˜ƒNow๎˜ƒtransmit๎˜ƒboth๎˜ƒthe๎˜ƒ
message๎˜ƒand๎˜ƒthe๎˜ƒCRC.๎˜ƒThe๎˜ƒrecipient๎˜ƒof๎˜ƒthe๎˜ƒtransmission๎˜ƒdoes๎˜ƒthe๎˜ƒsame๎˜ƒoperation๎˜ƒ(divides๎˜ƒthe๎˜ƒ
message๎˜ƒby๎˜ƒthe๎˜ƒsame๎˜ƒkey)๎˜ƒand๎˜ƒcompares๎˜ƒhis๎˜ƒCRC๎˜ƒwith๎˜ƒyours.๎˜ƒIf๎˜ƒthey๎˜ƒdiffer,๎˜ƒthe๎˜ƒmessage๎˜ƒmust๎˜ƒ
have๎˜ƒbeen๎˜ƒmangled.๎˜ƒIf,๎˜ƒon๎˜ƒthe๎˜ƒother๎˜ƒhand,๎˜ƒthey๎˜ƒare๎˜ƒequal,๎˜ƒthe๎˜ƒodds๎˜ƒare๎˜ƒpretty๎˜ƒgood๎˜ƒthat๎˜ƒthe๎˜ƒ
message๎˜ƒwent๎˜ƒthrough๎˜ƒuncorrupted.๎˜ƒMost๎˜ƒlocalized๎˜ƒcorruptions๎˜ƒ(burst๎˜ƒof๎˜ƒerrors)๎˜ƒwill๎˜ƒbe๎˜ƒcaught๎˜ƒ
using๎˜ƒthis๎˜ƒscheme.๎˜ƒ๎˜ƒ
๎˜ƒ
Not๎˜ƒall๎˜ƒkeys๎˜ƒare๎˜ƒequally๎˜ƒgood.๎˜ƒThe๎˜ƒlonger๎˜ƒthe๎˜ƒkey,๎˜ƒthe๎˜ƒbetter๎˜ƒerror๎˜ƒchecking.๎˜ƒOn๎˜ƒthe๎˜ƒother๎˜ƒ
hand,๎˜ƒthe๎˜ƒcalculations๎˜ƒwith๎˜ƒlong๎˜ƒkeys๎˜ƒcan๎˜ƒget๎˜ƒpretty๎˜ƒinvolved.๎˜ƒEthernet๎˜ƒpackets๎˜ƒuse๎˜ƒa๎˜ƒ32โ€bit๎˜ƒCRC๎˜ƒ
corresponding๎˜ƒto๎˜ƒdegreeโ€31๎˜ƒremainder๎˜ƒ(remember,๎˜ƒyou๎˜ƒneed๎˜ƒd๎˜ƒ+๎˜ƒ1๎˜ƒcoefficients๎˜ƒfor๎˜ƒa๎˜ƒdegreeโ€d๎˜ƒ
polynomial).๎˜ƒSince๎˜ƒthe๎˜ƒdegree๎˜ƒof๎˜ƒthe๎˜ƒremainder๎˜ƒis๎˜ƒalways๎˜ƒless๎˜ƒthan๎˜ƒthe๎˜ƒdegree๎˜ƒof๎˜ƒthe๎˜ƒdivisor,๎˜ƒthe๎˜ƒ
Ethernet๎˜ƒkey๎˜ƒmust๎˜ƒbe๎˜ƒa๎˜ƒpolynomial๎˜ƒof๎˜ƒdegree๎˜ƒ32.๎˜ƒA๎˜ƒpolynomial๎˜ƒof๎˜ƒdegree๎˜ƒ32๎˜ƒhas๎˜ƒ33๎˜ƒcoefficients๎˜ƒ
requiring๎˜ƒa๎˜ƒ33โ€bit๎˜ƒnumber๎˜ƒto๎˜ƒstore๎˜ƒit.๎˜ƒHowever,๎˜ƒsince๎˜ƒwe๎˜ƒknow๎˜ƒthat๎˜ƒthe๎˜ƒhighest๎˜ƒcoefficient๎˜ƒ(in๎˜ƒ
front๎˜ƒof๎˜ƒx32)๎˜ƒis๎˜ƒ1,๎˜ƒwe๎˜ƒdon't๎˜ƒhave๎˜ƒto๎˜ƒstore๎˜ƒit.๎˜ƒThe๎˜ƒkey๎˜ƒused๎˜ƒby๎˜ƒthe๎˜ƒEthernet๎˜ƒis๎˜ƒ0x04c11db7.๎˜ƒIt๎˜ƒ
corresponds๎˜ƒto๎˜ƒthe๎˜ƒpolynomial:๎˜ƒ
x32๎˜ƒ+๎˜ƒx26๎˜ƒ+๎˜ƒ...๎˜ƒ+๎˜ƒx2๎˜ƒ+๎˜ƒx๎˜ƒ+๎˜ƒ1๎˜ƒ๎˜ƒ
๎˜ƒ
If๎˜ƒwe๎˜ƒdenote๎˜ƒthe๎˜ƒoriginal๎˜ƒmessage๎˜ƒpolynomial๎˜ƒby๎˜ƒM๎˜ƒ(x),๎˜ƒthe๎˜ƒkey๎˜ƒpolynomial๎˜ƒby๎˜ƒK๎˜ƒ(x)๎˜ƒand๎˜ƒthe๎˜ƒ
CRC๎˜ƒby๎˜ƒR๎˜ƒ(x)๎˜ƒ(remainder)๎˜ƒwe๎˜ƒhave:๎˜ƒ
๎˜ƒ
M๎˜ƒ*๎˜ƒx32๎˜ƒ=๎˜ƒQ๎˜ƒ(x)๎˜ƒ*๎˜ƒK๎˜ƒ(x)๎˜ƒ+๎˜ƒR๎˜ƒ(x)๎˜ƒ
๎˜ƒ
Now๎˜ƒadd๎˜ƒthe๎˜ƒCRC๎˜ƒto๎˜ƒthe๎˜ƒaugmented๎˜ƒmessage๎˜ƒand๎˜ƒsend๎˜ƒit๎˜ƒaway.๎˜ƒWhen๎˜ƒthe๎˜ƒrecipient๎˜ƒ
calculates๎˜ƒthe๎˜ƒCRC๎˜ƒfor๎˜ƒthis๎˜ƒsum,๎˜ƒand๎˜ƒthere๎˜ƒwas๎˜ƒno๎˜ƒtransmission๎˜ƒerror,๎˜ƒhe๎˜ƒwill๎˜ƒget๎˜ƒzero.๎˜ƒThat's๎˜ƒ
because:๎˜ƒ
๎˜ƒ
M๎˜ƒ*๎˜ƒx32๎˜ƒ+๎˜ƒR๎˜ƒ(x)๎˜ƒ=๎˜ƒQ๎˜ƒ(x)๎˜ƒ*๎˜ƒK๎˜ƒ(x)๎˜ƒ(no๎˜ƒremainder!)๎˜ƒ
๎˜ƒ
You๎˜ƒmight๎˜ƒthink๎˜ƒI๎˜ƒmade๎˜ƒa๎˜ƒsign๎˜ƒmistakeโ€โ€it๎˜ƒshould๎˜ƒbe๎˜ƒโ€R๎˜ƒ(x)๎˜ƒon๎˜ƒthe๎˜ƒleft.๎˜ƒRemember,๎˜ƒhowever,๎˜ƒ
that๎˜ƒin๎˜ƒarithmetic๎˜ƒmodulo๎˜ƒ2๎˜ƒaddition๎˜ƒand๎˜ƒsubtraction๎˜ƒare๎˜ƒthe๎˜ƒsame!๎˜ƒ
๎˜ƒ
๎˜ƒ
๎˜ƒ
Calculating๎˜ƒthe๎˜ƒCRC๎˜ƒ
The๎˜ƒCRC๎˜ƒalgorithm๎˜ƒrequires๎˜ƒthe๎˜ƒdivision๎˜ƒof๎˜ƒthe๎˜ƒmessage๎˜ƒpolynomial๎˜ƒby๎˜ƒthe๎˜ƒkey๎˜ƒpolynomial.๎˜ƒThe๎˜ƒ
straightforward๎˜ƒimplementation๎˜ƒfollows๎˜ƒthe๎˜ƒidea๎˜ƒof๎˜ƒlong๎˜ƒdivision,๎˜ƒexcept๎˜ƒthat๎˜ƒit's๎˜ƒmuch๎˜ƒsimpler.๎˜ƒ
The๎˜ƒcoefficients๎˜ƒof๎˜ƒour๎˜ƒpolynomials๎˜ƒare๎˜ƒones๎˜ƒand๎˜ƒzeros.๎˜ƒWe๎˜ƒstart๎˜ƒwith๎˜ƒthe๎˜ƒleftmost๎˜ƒcoefficient๎˜ƒ
(leftmost๎˜ƒbit๎˜ƒof๎˜ƒthe๎˜ƒmessage).๎˜ƒIf๎˜ƒit's๎˜ƒzero,๎˜ƒwe๎˜ƒmove๎˜ƒto๎˜ƒthe๎˜ƒnext๎˜ƒcoefficient.๎˜ƒIf๎˜ƒit's๎˜ƒone,๎˜ƒwe๎˜ƒ
subtract๎˜ƒthe๎˜ƒdivisor.๎˜ƒExcept๎˜ƒthat๎˜ƒsubtraction๎˜ƒmodulo๎˜ƒ2๎˜ƒis๎˜ƒequivalent๎˜ƒto๎˜ƒexclusive๎˜ƒor,๎˜ƒso๎˜ƒit's๎˜ƒvery๎˜ƒ
simple.๎˜ƒ๎˜ƒ
๎˜ƒ
docsity.com
pf2

Partial preview of the text

Download CRC Mathematics-Data Communication-Lecture Handouts and more Lecture notes Data Communication Systems and Computer Networks in PDF only on Docsity!

CRCโ€Mathematics

CRC

Take a binary message and convert it to a polynomial then divide it by another predefined polynomial called the key. The remainder from this division is the CRC. Now transmit both the message and the CRC. The recipient of the transmission does the same operation (divides the message by the same key) and compares his CRC with yours. If they differ, the message must have been mangled. If, on the other hand, they are equal, the odds are pretty good that the message went through uncorrupted. Most localized corruptions (burst of errors) will be caught using this scheme. Not all keys are equally good. The longer the key, the better error checking. On the other hand, the calculations with long keys can get pretty involved. Ethernet packets use a 32 โ€bit CRC corresponding to degreeโ€ 31 remainder (remember, you need d + 1 coefficients for a degreeโ€d polynomial). Since the degree of the remainder is always less than the degree of the divisor, the Ethernet key must be a polynomial of degree 32. A polynomial of degree 32 has 33 coefficients requiring a 33 โ€bit number to store it. However, since we know that the highest coefficient (in front of x^32 ) is 1, we don't have to store it. The key used by the Ethernet is 0x04c11db7. It corresponds to the polynomial: **x 32

  • x 26
  • ... + x 2
  • x + 1** If we denote the original message polynomial by M (x) , the key polynomial by K (x) and the CRC by R (x) (remainder) we have: M * x 32 = Q (x) * K (x) + R (x) Now add the CRC to the augmented message and send it away. When the recipient calculates the CRC for this sum, and there was no transmission error, he will get zero. That's because: M * x 32 + R (x) = Q (x) * K (x) (no remainder!) You might think I made a sign mistakeโ€โ€it should be โ€R (x) on the left. Remember, however, that in arithmetic modulo 2 addition and subtraction are the same! Calculating the CRC The CRC algorithm requires the division of the message polynomial by the key polynomial. The straightforward implementation follows the idea of long division, except that it's much simpler. The coefficients of our polynomials are ones and zeros. We start with the leftmost coefficient (leftmost bit of the message). If it's zero, we move to the next coefficient. If it's one, we subtract the divisor. Except that subtraction modulo 2 is equivalent to exclusive or, so it's very simple.

docsity.com

Let's do a simple example, dividing a message 100110 by the key 101. Remember that the corresponding polynomials are x^5 + x 2 + x and x^2 + 1. Since the degree of the key is 2, we start by appending two zeros to our message. 100110 00 / 101 101 111 101 100 101 100 101 01 We don't even bother calculating the quotient, all we need is the remainder (the CRC), which is 01 in this case. The original message with the CRC attached reads 10011001. You can easily convince it that it is divisible by the key, 101, with no remainder.

The mathematics of CRCs

The mechanics of computing an nโ€bit binary CRC are simple. The bits representing the input are lined up in a row, and the (n+1)โ€bit pattern representing the CRC's divisor (called a "polynomial" because of the tools used in the mathematical analysis of CRCs) is positioned underneath the leftโ€hand end of the row. Here is the starting position for computing a 3 โ€bit CRC: 11010011101100 <โ€โ€โ€ input 1011 <โ€โ€โ€ divisor (4 bits) If the input bit above the leftmost divisor bit is 1, the divisor is exclusiveโ€ORed into the input (in other words, the input bit above each 1 โ€bit in the divisor is toggled). The divisor is then shifted one bit to the right, and the process is repeated until the divisor reaches the rightโ€hand end of the input row: 00000000000101 <โ€โ€โ€ remainder (3 bits) 1011 <โ€โ€โ€ divisor Since the leftmost divisor bit zeroed every input bit it touched, when this process ends the only bits in the input row that can be nonzero are the n bits at the rightโ€hand end of the row. These n bits are the remainder of the division step, and will also be the value of the CRC function (unless the CRC specification calls for some post processing). CRC8 Polynomial: X^8 + X^4 + X^3 + X^2 +

docsity.com