home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / sci / crypt / 7140 < prev    next >
Encoding:
Text File  |  1993-01-25  |  5.4 KB  |  129 lines

  1. Newsgroups: sci.crypt
  2. Path: sparky!uunet!paladin.american.edu!europa.asd.contel.com!NewsWatcher!user
  3. From: levesque@rocky.ndhm.gtegsc.com (Allen Levesque)
  4. Subject: CRC Encoding & Decoding
  5. Message-ID: <levesque-250193145752@192.147.5.16>
  6. Followup-To: CRC-16 Inquiry from Paul Rolland
  7. Sender: news@europa.asd.contel.com (News)
  8. Nntp-Posting-Host: rocky.ndhm.gtegsc.com
  9. Organization: GTE Government Systems
  10. Date: Mon, 25 Jan 1993 20:00:32 GMT
  11. Lines: 116
  12.  
  13. THIS IS POSTED IN RESPONSE TO AN INQUIRY FROM PAUL ROLLAND
  14. (rol@grasp1.univ-lyon.fr) RE ALGORITHMS FOR CRC CODES.  PERHAPS THIS MAY
  15. QUALIFY FOR INCLUSION IN A LIST OF FAQ'S.
  16.  
  17. Subject: Encoding and Decoding CRC Codes
  18. Date: January 25, 1993
  19. From: levesque@rocky.ndhm.gtegsc.com
  20.  
  21. ENCODING AND DECODING CYCLIC REDUNDANCY CHECK (CRC) CODES
  22.  
  23.    A CRC-coded "message" consists of a specific number of data bits and a
  24. set of check bits, sometimes called the Frame Check Sequence (in HDLC
  25. parlance).  If we let n be the total number of bits in the coded message,
  26. and k the number of data bits, then n-k equals the number of check bits (e.
  27. g., n-k = 16 bits when CRC-16 is used, and so forth).
  28.  
  29.    The coded message is constructed from two polynomials, the first an
  30. algebraic representation of the data sequence and the second the CRC
  31. generator polynomial.  It is conventional to denote the data polynomial as
  32. G(X) and the code generator polynomial as P(X).  Thus the k-bit data
  33. sequence is represented as
  34.  
  35. G(X) = X^(k-1) + X^(k-2) + ... + X + 1,          where X^0 = 1.
  36.  
  37. As an example, the data sequence 10011 is represented as X^4 + + X + 1. 
  38. Similarly, we arrange the CRC generator polynomial with highest power at
  39. the left, such as
  40.  
  41. P(X) = X^16 + X^15 + X^2 + 1            (CRC-16).
  42.  
  43.    Stated simply, given a data polynomial G(X) and a CRC generator
  44. polynomial P(X), the encoding procedure is to construct a coded message
  45. polynomial F(X) that is evenly divisible by P(X).  To accomplish this, we
  46. first multiply the data polynomial G(X) by X^(n-k), which has the effect of
  47. "shifting the data sequence to the left", leaving n-k open bit positions at
  48. the right-hand end; we then fill those positions with the remainder after
  49. dividing the shifted version of G(X) by the CRC generator polynomial.  The
  50. steps are as follows:
  51.  
  52. 1.   Multiply the data sequence G(X) by X^(n-k), where n-k is the degree of
  53. the CRC generator polynomial.
  54.  
  55. 2.   Divide the resulting product [X^n-k][G(X)] by the generator polynomial
  56. P(X), producing a quotient and a remainder, which we call C(X).
  57.  
  58. 3.   Discard the quotient and add the remainder C(X) to the product,
  59. thereby producing the coded message polynomial F(X) =  [X^n-k][G(X)] +
  60. C(X).
  61.  
  62.    The division is modulo-2 polynomial division, that is, in binary with no
  63. carries or borrows.  Note that the bit length of the remainder C(X) is one
  64. less than the bit length of the CRC polynomial.  This is always the case
  65. since, for example, any remainder after division by a degree-16 polynomial
  66. cannot have degree greater than 15.     
  67.  
  68.    It is a simple matter to show that F(X) =  [X^n-k][G(X)] + C(X) is
  69. evenly divisible by the CRC generator polynomial.  The remainder of F(X) is
  70. the sum of the remainders of the two terms in F(X).  The remainder of the
  71. first term is of course C(X).  The remainder of the second term is simply
  72. the second term C(X) itself.  Summing the two remainders modulo-2 produces
  73. zero, QED.
  74.  
  75. EXAMPLE:
  76.  (example adapted from McNamara, ref. 5)
  77.  
  78. 1.   Given: Data polynomial  G(X) = 110011 = X^5 + X^4 + X + 1
  79.      Generator polynomial P(X) = 11001 = X^4 + X^3 + 1
  80.      G(X) contains 6 data bits;  P(X) contains 5 bits, thus there are 
  81.      4 check-bit positions, and n-k =4, so that n=10.
  82.  
  83. 2.   Multiplying the data sequence G(X) by X^4 yields the product:
  84.      X^9 + X^8 + X^5 + X^4   (binary is 1100110000, ten bits long).
  85.  
  86. 3.   Dividing the product by P(X) gives a quotient of 100001 and
  87.      a remainder C(X) = 1001.
  88.  
  89. 4.   The quotient is discarded and the remainder C(X) is added 
  90.     to the product to produce the coded message 
  91.      F(X) = 1100111001.
  92.  
  93.    The coded message is transmitted over a channel, and at the receive end,
  94. the decoder divides the received message by the CRC generator polynomial. 
  95. If no errors occurred in transit, the division will produce the all-zeros
  96. remainder, and the data bits are accepted as error-free.  A non-zero
  97. remainder indicates detected errors.  
  98.  
  99.    Much of the literature describes CRC encoding and decoding using
  100. shift-register long-division algorithms.  However, software algorithms
  101. (mainly table drive) have also been documented.  Some references are
  102. provided below.
  103.  
  104. REFERENCES:
  105.  
  106. 1.   Boudreau and Steen, "Cyclic Redundancy Checking by Program," 
  107.      AFIPS Proceedings, Vol. 39, 1971.
  108. 2.   Higginson and Kirstein, "On the Computation of Cyclic Redundancy
  109. Checks by Program,"  The Computer Journal (British), VJol 16, No. 1, Feb
  110. 1973.
  111. 3.   Marton and Frambs, "A Cyclic Redundancy Checking (CRC) Algorithm," 
  112.    Honeywell Computer Journal, Vol. 5, No. 3, 1971.
  113. 4.   Wecker, S., "A Table-Lookup Algorithm for Software Computation of
  114. Cyclic Redundancy Check (CRC)," Digital Equipment Corporation memorandum,
  115. 1974.
  116. [Reference cited in McNamara, ref. below.]
  117. 5.   McNamara, J. E., "Technical Aspects of Data Communication," 2nd
  118. edition, 
  119.      Digital Press, Bedford, Massachusetts, 1982.
  120. 6.   Davies and Barber, "Computer Networks and Their Protocols," 
  121.      J. Wiley & Sons, 1979.
  122.  
  123. END
  124.  
  125.  
  126. ALLEN LEVESQUE, GTE GOVERNMENT SYSTEMS CORP., WALTHAM, MASS. USA,
  127. TEL: (617)466-3729, FAX: (617)466-3720, e-mail:
  128. Levesque@rocky.ndhm.gtegsc.com
  129.