Search This Blog

Loading...

Implementation Of CRC C Program

Algorithm Steps:


Step 1: Declare int crc 16, SHIFT_CRC, shift Byte, Byte_SIZE as global variables.
Step 2: Input the data in a file.
Step 3: perform the crc computation using cal CRC 16 ().
Step 4: In cal CRC 16 each character from input shifted with shift-byte where value 987.
Step 5: Output of step 4 and step 5 are exclusive.
Step 6: store in a temporary variable.
Step 7: Byte value is now left_shifted by 1.
Step 8: The loop is repeated for the Byte_size.
Step 9: The computed crc is display as output in screen.
 #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:
Enter Data: 11110110101
Enter key: 111010

Quotient is 1001001000
Remainder is 00000
Final data is: 1111011010100000 

No comments:

Post a Comment