Headlines
Loading...
Data Communication network(DCN) Program to implement CRC method

Data Communication network(DCN) Program to implement CRC method

Program to implement CRC method
#include<stdio.h>
#include<conio.h>
void compute_crc(int div[],int v,int d,int ch)
{
 int f=0,n,i,j,base=0,temp,final[20],did[20]={0},sum=0,rem[10]={0};
 switch(ch)
{
case 1:
printf("Enter the dividend:");
break;
case 2:
printf("Enter the recieved stream :");
break;
}
 for(i=0;i<d;i++)
 {
  scanf("%d",&did[i]);
 }

 j=0;
 for(i=0;i<d;i++);

 if(ch==1)
 {
 for(temp=i;temp<d+(v-1);temp++)
{
did[temp]=0;
}
 }
 else
 {
 for(temp=i;temp<d+(v-1);temp++)
{
scanf("%d",&did[temp]);
}
 }
 printf("\nPrinting The final dividend:\n");

 f=d+v-1;
 for(i=0;i<f;i++)
 {
printf("%d",did[i]);
final[i]=did[i];
 }
 i=v;
 for(;i<=f;)
    {
for(j=0;j<v;j++)
{

if(final[base]==div[j])
final[base]=0;
else
final[base]=1;
base++;
}

base=i-v;
j=0;
while(j<v)
{
if(final[base]==1)
break;
base++;
j++;
i++;
}
    }
    j=0;
    printf("\n\nRemainder(CRC):");
    for(i=d;i<f;i++)
{
rem[j]=final[i];

printf("%d",rem[j]);
j++;
}
    if(ch==1)
{
printf("\nSent data stream:");
for(i=0;i<d;i++)
{
printf("%d",did[i]);
}
for(i=0;i<j;i++)
{
printf("%d",rem[i]);
}
}
    if(ch==2)
{
for(i=0;i<j;i++)
{
sum=sum+rem[i];
}

if(sum==0)
printf("\nRecieved string is correct");
else
printf("\nRecieved string is incorrect");
}
    printf("\n================================================\n");
}
void main()
{
 int i,v,div[20],d,len,temp;
 clrscr();
 printf("                    CYCLIC REDUNDANCY CHECK PROGRAM\n");
printf("\nEnter the no. of bits for divisor:");
 scanf("%d",&v);
 printf("\nEnter the divisor:");
 for(i=0;i<v;i++)
 {
  scanf("%d",&div[i]);
 }
 printf("\n\n================================================");
 printf("\n1.Senders side:");
 printf("\n================================================\n");
 printf("\nEnter the no. of bits for dividend:");
 scanf("%d",&d);
 compute_crc(div,v,d,1);
 printf("\n\n================================================");
 printf("\n2.Recievers side:");
 printf("\n================================================\n");
 printf("\nEnter the length of the recieved data stream :");
 scanf("%d",&len);
 temp=d+v-1;
 if(len==temp)
{
compute_crc(div,v,d,2);
}
 else
{
printf("Sorry!!! Length of string invalid!!!");
}
 getch();
}









Output:
                    CYCLIC REDUNDANCY CHECK PROGRAM

Enter the no. of bits for divisor:3

Enter the divisor:1 0 1


================================================
1.Senders side:
================================================

Enter the no. of bits for dividend:5
Enter the dividend:1 0 1 0 1

Printing The final dividend:
1010100

Remainder(CRC):01
Sent data stream:1010101
================================================


================================================
2.Recievers side:
================================================

Enter the length of the recieved data stream :7
Enter the recieved stream :1 0 1 0 1 0 0

Printing The final dividend:
1010100

Remainder(CRC):01
Recieved string is incorrect
================================================

 

*** PLEASE checkout the Best deals from for top sites like Amazon, Flipkart etc ***