EXP6
EXP6
PART A
Experiment No. 06
A.1 Objective:
Implementation of a Cyclic Redundancy Code (CRC) generator and checker using any higher level
language
A.2 Prerequisite:
• Knowledge about PAN, LAN and NW Elements.
• Knowledge of Programming Languages.
• Binary arithmetic’s.
• Error types and their detection and correction.
• Concept of Programming, Analysis, Design, Simulation and Modelling
A.3 Outcome:
After successful completion of this experiment students will be able to
A.4 Theory/Tutorial:
The Cyclic Redundancy Check algorithm checks for errors and verifies the accuracy of the data
delivered by the sender. CRC requires a generator polynomial in order to compute the check value using
binary division in addition to the data that has to be transferred. To ensure that the data is genuine, the
check value or CRC is sent with it to the recipient.
The degree of the polynomial can be used as the bit locations to represent the data that will be conveyed
to the recipient in polynomial form.
Binary data can also be used to represent the generating polynomial. The degree of the data polynomial
must be less than the degree of the generator polynomial and must be larger than 0. Based on the degree
of the generating polynomial, the CRC may be divided into several standards. Using a generator
polynomial of degree 8 for the CRC-8 standard and degree 16 for the CRC-16 standard.
An example generator polynomial is of the form like x3 + x + 1. This generator polynomial represents
key 1011. Another example is x2 + 1 that represents key 101.
n : Number of bits in data to be sent from sender side. k : Number of bits in the key obtained
Sender Side (Generation of Encoded Data from Data and Generator Polynomial (or Key)):
1. The binary data is first augmented by adding k-1 zeros in the end of the data
2. Use modulo-2 binary division to divide binary data by the key and store remainder of division.
3. Append the remainder at the end of the data to form the encoded data and send the same
Receiver Side (Check if there are errors introduced in transmission)
Perform modulo-2 division again and if the remainder is 0, then there are no errors.
Modulo 2 Division:
The process of modulo-2 binary division is the same as the familiar division process we use for
decimal numbers. Just that instead of subtraction, we use XOR here.
• In each step, a copy of the divisor (or data) is XORed with the k bits of the dividend (or
key).
• The result of the XOR operation (remainder) is (n-1) bits, which is used for the next step
after 1 extra bit is pulled down to make it n bits long.
• When there are no bits left to pull down, we have a result. The (n-1)-bit remainder which is
appended at the sender side
References:
• https://www.javatpoint.com/computer-network-error-detection
PART B
#include<stdio.h>
#include<string.h>
// length of the generator polynomial
#define N strlen(gen_poly)
// data to be transmitted and received
char data[28];
// CRC value
char check_value[28];
// generator polynomial
char gen_poly[10];
// variables
int data_length,i,j;
// function that performs XOR operation
void XOR(){
// if both bits are the same, the output is 0
// if the bits are different the output is 1
for(j = 1;j < N; j++)
check_value[j] = (( check_value[j] == gen_poly[j])?'0':'1');
}
// Function to check for errors on the receiver side
void receiver(){
// get the received data
printf("Enter the received data: ");
scanf("%s", data);
// Cyclic Redundancy Check
crc();
// Check if the remainder is zero to find the error
for(i=0;(i<N-1) && (check_value[i]!='1');i++);
if(i<N-1)
{
printf("\n\n Error detected\n");
printf(" ************\n");
}
else
{
printf("\n\n No error detected\n");
printf(" ***************\n");
}
}
void crc(){
// initializing check_value
for(i=0;i<N;i++)
check_value[i]=data[i];
do{
// check if the first bit is 1 and calls XOR function
if(check_value[0]=='1')
XOR();
// Move the bits by 1 position for the next computation
for(j=0;j<N-1;j++)
check_value[j]=check_value[j+1];
// appending a bit from data
check_value[j]=data[i++];
}while(i<=data_length+N-1);
// loop until the data ends
}
int main()
{
printf("\nEnter data to be transmitted: ");
scanf("%s",data);
printf("\n Enter the Generating polynomial: ");
// get the generator polynomial
scanf("%s",gen_poly);
// find the length of data
data_length=strlen(data);
// appending n-1 zeros to the data
for(i=data_length;i<data_length+N-1;i++)
data[i]='0';
printf("\n ");
// print the data with padded zeros
printf("\n Data padded with n-1 zeros : %s",data);
// Cyclic Redundancy Check
crc();
// print the computed check value
printf("\n CRC or Check value is : %s",check_value);
// Append data with check_value(CRC)
for(i=data_length;i<data_length+N-1;i++)
data[i]=check_value[i-data_length];
// printing the final data to be sent
printf("\n Final data to be sent : %s",data);
printf("\n \n");
// Calling the receiver function to check errors
receiver();
return 0;
}
We get the transmitted data by using the Cyclic Redundancy checker in high level language.
B.3 Conclusion:
We learned about Cyclic Redundancy checker and XOR operation and implementation.
B.4 Question of Curiosity
Types of Errors
In
a frame, there is only one bit, anywhere though, which is corrupt.
Multiplebits error
Frame is received with more than one bits in corrupted state. Burst error
- Odd Parity: Ensures the total number of set bits in a binary sequence, including the
parity bit, is odd.
- Limitation of Single Parity Check: Detects but cannot correct errors; limited to
detecting odd numbers of errors.
In short, even and odd parity define whether the total number of set bits is even or
odd. Single parity check detects but doesn't correct errors, while two-dimensional
parity check is limited in detecting certain error patterns.
- Error Checker: Verifies the integrity of transmitted data by checking the redundancy
(parity) bits and identifying errors if present.
In short, the redundant bit generator adds extra bits for error detection, and the error
checker verifies data integrity by examining these redundancy bits.
6. State the working of CRC error detection method with example of your own?
Ans - A cyclic redundancy check (CRC) is an error-detecting code
commonly used indigital networks and storage devices to detect accidental
changes to raw data.
Blocks of data entering these systems get a short check value attached, based on the
remainder of a polynomial division of their contents.
CRC Generator-
Example
Thus, for the given CRC generator, the corresponding binary pattern is 11011011.