Home / C / C Program to implement CRC (Cyclic Redundancy Code)

C Program to implement CRC (Cyclic Redundancy Code)

This is a C Program for implementing CRC (Cyclic Redundancy Check Code)

 #include <stdio.h>
 #include <conio.h>
 #include <string.h>
 void main()
 {
 int i,j,keylen,msglen;
 char input[100], key[30],temp[30],quot[100],rem[30],key1[30];
 clrscr();
 printf("Enter Data: ");
 gets(input);
 printf("Enter Key: ");
 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("\nQuotient is ");
 for(i=0;i<msglen;i++)
 printf("%c",quot[i]);
 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]);
 getch();
 }

Output:

tags: Error Checking and Correction, CRC program, C program of CRC,Cyclic Redundancy Check Code, protocols,Β binary division
Also See:   C Program for Bit Stuffing

Check Also

How to Solve Linear Equation in One Variable In C Programming?

C Program to Solve any Linear Equation in One Variable Find complete C program to ...

12 comments

  1. Thank you.
    RCOEM 5th sem.

  2. thanks a loottttttt! <3 <3 πŸ˜‰

  3. I learnt a lot πŸ™‚ thanks a ton πŸ™‚ <3 πŸ˜‰

  4. this helps a lot

  5. thank a lott!!!
    loved using this site!
    helped me a lot
    πŸ™‚

  6. thanks a lot!!!
    it really helps me..

  7. This Program for CRC(Cyclic Redundancy Code Check) is 100% correct and has been tested by many people. Here is a C program for CRC but will update more methods soon and in other languages too.

  8. can u provide me embedded c code?

  9. the above code is completely wrong if the i/p sequence is 01010101000 key 1011

Leave a Reply

Your email address will not be published. Required fields are marked *