Java

Saturday, 21 February 2015

Implement the error detecting code cycle redundancy check of dates link layer using valancy polinomial like crc-12,crc-16,crc-ccit

program:

#include<iostream.h>
#include<string.h>
#include<conio.h>
#define N strlen(g)
char t[28],cs[25],g[28];
int a,e,c,b;
void xor()
{
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[c];
do
{
if(cs[0]=='1')
xor();
for(c=0;c<n-1;c++)
cs[c]=cs[c+1];
cs[c]=t[e++];
}
while(e<=a+N-1);
}
void main()
{
int flag=0;
clrscr();
{
printf("\n 1.crc 12 \n 2.crc 16 \n 3.crc ccit \n exit\n\n enter your option:");
scanf("%d",&b);
switch(b)
{
case 1:strcpy(g,"1100000001111");
break;
case 2:strcpy(g,"11000000000000101");
break;
case 3:strcpy(g,"10000100000010000");
break;
case 4:return 0;
}
printf("\n enter data");
scanf("%s",t);
printf("\n.........\n");
printf("\n generating polynomials%",g);
a=strlen(t);
for(e=a;e<a+N-1;e++)
t[e]='0';
printf("\n.........\n");
printf(\n modified data is%s",t);
printf("\n.........\n");
crc();
printf("check sum is%s",a);
for(e=0;e<a+N-1;e++)
t[e]=cs[e-a];
printf("\n........\n");
print("\n trust error detection 0(yes)1(no)?:");
scanf("%d",e);
if(e==0)
{
do
{
printf("\n\t enter the position where error is to be inserted:");
scanf("%d",&e);
}
while(e==0||e>a+N-1)
t[e-1]=(t[e-1]=='0')?'1';'0';
printf("\n........\n);
printf("\n\t errorneous data is:%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("no error detected\n\n");
printf("\n..........\n");
}
while(flag!=1);
getch();
}

No comments:

Post a Comment