Youth Talent Auzzar

Pages

Computer Network: Cyclic Redundancy Check(CRC) in C Programming

A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital 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 apolynomial division of their contents; on retrieval the calculation is repeated, and corrective action can be taken against presumed data corruption if the check values do not match.

Lets start...

#include<stdio.h>

#include<conio.h>

void main()

{

int
a[20],c[20],d[20],aux[20],r,i,j,l,in,flag,choice,key;

clrscr();

printf("\n ENTER
THE SIZE OF DATA WORD : ");

scanf("%d",&l);

printf("\n ENTER
THE DATA WORD : ");

for(i=0; i<l; i++)

scanf("%d",&a[i]);

printf("\n ENTER
THE NUMBER OF REDUNDANT BITS : ");

scanf("%d",&r);

printf("\n ENTER
THE DIVISOR : ");

for(i=0; i<(r+1);
i++)

scanf("%d",&d[i]);

for(i=0; i<(l+r);
i++){

if(i<l)
c[i]=a[i];

else c[i]=0;

}

printf("\n\n ...
GENERATOR MODULE ... \n");

printf("\n\n THE
INTERMEDIATE CODE WORD IS : ");

for(i=0; i<(l+r);
i++)

printf("%d
",c[i]);

for(i=0; i<(l+r);
i++)

aux[i]=c[i];

for(i=0; i<l; i++){

in=1;

if(c[i]==1){

for(j=i+1;
j<(i+l); j++){

c[j]=c[j]^d[in];

in++;

}

}

else{

for(j=i+1;
j<(i+l); j++)

c[j]=c[j]^0;

}

}

printf("\n\n THE
REMAINDER AFTER DIVISION IS : ");

for(i=l; i<(l+r);
i++)

printf("%d
",c[i]);

printf("\n\n
SENDER CODE WORD : ");

for(i=0; i<(l+r);
i++){

if(i<l)
c[i]=aux[i];

printf("%d
",c[i]);

}

printf("\n\n\n
PRESS 1 IF YOU WANT TO CHANGE A BIT OR 0 TO CONTINUE : ");