Cyclic Redundancy Check (CRC) is a powerful error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data. It is particularly good at detecting common errors caused by noise in transmission channels.
CRC is an error detection technique based on binary division. Unlike the checksum scheme, which is based on addition, CRC is based on polynomial division in a finite field.
In CRC, a sequence of redundant bits, called the CRC bits, are appended to the end of the data unit so that the resulting data unit becomes exactly divisible by a predetermined binary number. At the destination, the incoming data unit is divided by the same number. If at this step there is no remainder, the data unit is assumed to be correct and is therefore accepted. A remainder indicates that the data unit has been damaged in transit and therefore must be rejected.
The CRC calculation is based on polynomial arithmetic, specifically polynomial division over the finite field GF(2) (i.e., the set {0,1} using modulo 2 arithmetic).
Here's how CRC works:
Define a Generator Polynomial: A key polynomial is chosen based on the desired error detection properties. This is known as the generator polynomial.
Append Zeros: The message is first augmented by appending k-1 zeros to it, where k is the degree of the generator polynomial.
Perform Division: The augmented message is divided by the generator polynomial using modulo-2 division.
Calculate Remainder: The remainder from the division is the CRC.
Transmit Data with CRC: The original message is transmitted along with the CRC.
Verify at Receiver: The receiver divides the received message (including the CRC) by the same generator polynomial. If the remainder is zero, the message is accepted; otherwise, it is rejected.
At the receiver, the entire received message (101000000) is divided by the generator polynomial (1001). If there are no errors, the remainder should be zero.
These polynomials are chosen for their ability to detect specific types of errors, such as single-bit errors, double-bit errors, odd number of errors, and burst errors.
CRC can be implemented in hardware or software. Hardware implementations are typically faster and are used in high-speed communication systems. Software implementations are more flexible and are used in applications where speed is not critical.
Here's a simple Python implementation of CRC:
def crc_remainder(input_bitstring, polynomial_bitstring, initial_filler): """Calculate the CRC remainder of a string of bits using a chosen polynomial. initial_filler should be '1' or '0'.""" len_input = len(input_bitstring) initial_padding = initial_filler * (len(polynomial_bitstring) - 1) input_padded_array = list(input_bitstring + initial_padding) polynomial_bitstring_array = list(polynomial_bitstring) for i in range(len_input): if input_padded_array[i] == '1': for j in range(len(polynomial_bitstring)): input_padded_array[i + j] = str(int(input_padded_array[i + j]) ^ int(polynomial_bitstring_array[j])) return ''.join(input_padded_array)[len_input:]def crc_check(input_bitstring, polynomial_bitstring, check_value): """Calculate the CRC check of a string of bits using a chosen polynomial.""" polynomial_bitstring = polynomial_bitstring.lstrip('0') len_input = len(input_bitstring) initial_padding = check_value input_padded_array = list(input_bitstring + initial_padding) polynomial_bitstring_array = list(polynomial_bitstring) for i in range(len_input): if input_padded_array[i] == '1': for j in range(len(polynomial_bitstring)): input_padded_array[i + j] = str(int(input_padded_array[i + j]) ^ int(polynomial_bitstring_array[j])) remainder = ''.join(input_padded_array)[len_input:] return remainder == '0' * len(remainder)# Example usagedata = "1010000"polynomial = "1001" # x^3 + 1crc = crc_remainder(data, polynomial, '0')print(f"CRC: {crc}")# Check if data is corruptedreceived_data = data + crcprint(f"Is data valid: {crc_check(data, polynomial, crc)}")
High Error Detection Capability: CRC can detect a wide range of errors, including single-bit errors, double-bit errors, odd number of errors, and burst errors.
Efficiency: CRC is computationally efficient and can be implemented in hardware for high-speed applications.
Standardization: CRC algorithms are standardized, making them widely compatible across different systems.
Robustness: CRC is robust against common types of noise and interference in communication channels.
Cyclic Redundancy Check (CRC) is a powerful error detection technique that is widely used in digital networks and storage devices. It provides excellent error detection capabilities and is computationally efficient. While it cannot correct errors, it can detect a wide range of errors, making it an essential tool for ensuring data integrity in communication systems.
Test Your Knowledge
Take a quiz to reinforce what you've learned
Exam Preparation
Access short and long answer questions for written exams