Cyclic Redundency Check in linux

To write a C program to perform the  CRC computation using linux environment

Step1: Start the program.
Step2: Declare the variables and array of values.
Step3: Get the bits of data of the original values.
Step4: Get the divisor binary values for the original data.
Step5: By using for loop perform the process of CRC.
Step6: Finally the sending data’ s are printed.
Step7: Stop the program.

Source Code
 
// Comment
#include<stdio.h>
#include<string.h>
void xor(char a[10],char b[10],int len)
{
int i;
for(i=1;i<len;i++)
{
if(a[i]==b[i])
a[i-1]='0';
else
a[i-1]='1';
}
a[i]='\0';
}
main()
{
char a1[10],a2[10],t1[10],t2[10],t[5],res[15],c[15];
int n,len,tn,i;
printf("enter input string");
scanf("%s",a1);
printf("enter divisor");
scanf("%s",a2);
n=strlen(a1);
len=strlen(a2);
strcpy(res,a1);
for(i=0;i<len-1;i++)
{
c[i]='0';
}
c[i]='\0';
strcat(a1,c);

tn=strlen(a1);
strcpy(t1,a2);
for(i=0;i<len;i++)
{
t2[i]='0';
}
t2[i]='\0';
strncpy(t,a1,len);
for(i=len;i<=tn;i++)
{
xor(t,a2,len);
len=strlen(a2);
strcpy(res,a1);
for(i=n;i<n+len-1;i++)
{
a1[i]='0';
}
a1[i]='\0';
tn=strlen(a1);
strcpy(t1,a2);
for(i=0;i<len;i++)
{
t2[i]='0';
}
t2[i]='\0';
strncpy(t,a1,len);
for(i=len;i<=tn;i++)
{
xor(t,a2,len);
if(t[0]=='1')
strcpy(a2,t2);
else

strcpy(a2,t2);
t[len-1]=a1[i];
t[len]='\0';
}
strcat(res,t);
printf("the result is%s\n",res);
}
}






Output  
[t03it    @localhostt03it   ]$ cc crc.c
[t03it    @localhostt03it   ]$./a.out
enter input string 111011111
enter divisor 1101
the result is 111011111000000

1 comments:

commodity tips said...

very nice descriptive article stock tips and share tips

Post a Comment

Related Posts Plugin for WordPress, Blogger...