Experiment-4 Aim:-: Exp No: Date: Page No
Experiment-4 Aim:-: Exp No: Date: Page No
Date:
Experiment-4
Aim:- Write a Program to implement on a data set of characters the three CRC polynomials –
CRC 12, CRC 16 and CRC CCIP.
Description:- 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. The binary data
1010101 of length 7 can be, for instance, represented as, x7+x5+x3+1 As the value of that
representation is also 0, the bit value of 0 is not represented. The following are the CRC's
steps: the sender's side,
o The generating polynomial of length l and the data of length n are ready.
o The data that has to be delivered has (l-1) zeros attached to it.
o The binary version of the generating polynomial is used as the divisor in binary
division, with the data acting as the dividend. The check value is the remainder of the
binary division.
o The check value is added to the end of the data before sending the signal.
The n in this case refers to the generator polynomial's number of bits. Towards the receiver,
o The received data is divided once again using binary operations, with the data serving
as the dividend and the generating polynomial's binary counterpart serving as the
divisor.
o The data sent from the sender is error-free if the binary division's residual is zero. If
the residual does not equal zero, an error has tainted the signal.
Algorithm
o If the first bit is 1, then combine the generator polynomial with the first n bits of the
data in a XOR operation.
o Add a little portion of the data. Continue until all of the data's bits have been inserted.
Program:-
#define N strlen(g)
#include <stdio.h>
#include <string.h>
char t[28],cs[28],g[28];
int a;
int e;
int c;
int b;
voidxor()
for(c=1;c<N;c++)
cs[c]=((cs[c]==g[c])?'0':'1');
void crc()
for(e=0;e<N;e++)
cs[e]=t[e];
if(cs[0]=='1')
voidxor();
for(c=0;c<N-1;c++)
cs[c]=cs[c+1];
cs[c]=t[e++];
}while(e<=a+N-1);
int main()
int flag=0;
do{
scanf("%d",&b);
switch(b)
case 1:strcpy(g,"1100000001111");
break;
case 2:strcpy(g,"11000000000000101");
break;
case 3:strcpy(g,"10001000000100001");
break;
case 4:return 0;
scanf("%s",t);
printf("\n \n");
a=strlen(t);
for(e=a;e<a+N-1;e++)
t[e]='0';
printf("\n \n");
printf("\n \n");
crc();
printf("checksum is:%s",cs);
for(e=a;e<a+N-1;e++)
t[e]=cs[e-a];
printf("\n \n");
printf("\n \n");
scanf("%d",&e);
if(e==0)
do{
scanf("%d",&e);
while(e==0||e>a+N-1);
t[e-1]=(t[e-1]=='0')?'1':'0';
printf("\n \n");
printf("\n\terroneous data:%s\n",t);
crc();
for(e=0;(e<N-1)&&(cs[e]!='1');e++);
if(e<N-1)
printf("error detected\n\n");
else
printf("\n ");
}while(flag!=1);