In: Computer Science
We want to compute Cyclic Redundancy Check (CRC) for the given the data bits D=110001, generator G=1001, and 3 CRC bits (i.e., r=3),.
Explain the algorithm and implement the CRC computation in a programming language (e.g., C, C++, and Python) with the above setting.
Here I implemented CRC algorithm in C language.
#include <stdio.h>
#include <string.h>
int main()
{
int i,j,keylen,msglen;
char
input[100],key[30],temp[30],quot[100],rem[30],key1[30];
printf("Enter Data D: ");
gets(input);
printf("Enter Generator G: ");
gets(key);
keylen=strlen(key);
msglen=strlen(input);
strcpy(key1,key);
for (i=0;i<keylen-1;i++)
{
input[msglen+i]='0';
}
for (i=0;i<keylen;i++)
temp[i]=input[i];
for (i=0;i<msglen;i++)
{
quot[i]=temp[0];
if(quot[i]=='0')
for (j=0;j<keylen;j++)
key[j]='0';
else
for (j=0;j<keylen;j++)
key[j]=key1[j];
for(j=keylen-1;j>0;j--)
{
if(temp[j]==key[j])
rem[j-1]='0';
else
rem[j-1]='1';
}
rem[keylen-1]=input[i+keylen];
strcpy(temp,rem);
}
strcpy(rem,temp);
printf("\nRemainder is ");
for (i=0;i<keylen-1;i++)
printf("%c",rem[i]);
printf("\nFinal data is: ");
for (i=0;i<msglen;i++)
printf("%c",input[i]);
for (i=0;i<keylen-1;i++)
printf("%c",rem[i]);
return 0;
}
Output :