Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
26 views5 pages

CRC Program for CS Students

The document describes a C program to implement cyclic redundancy check (CRC). The program takes a data string and divisor as input, calculates the remainder by dividing the data by the divisor, and outputs the remainder. It also checks if the remainder is non-zero to detect any errors in the data. Key steps include appending zeros to the data, dividing bit-by-bit, storing the remainder, and checking if it is non-zero to detect errors.

Uploaded by

Aeydap
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views5 pages

CRC Program for CS Students

The document describes a C program to implement cyclic redundancy check (CRC). The program takes a data string and divisor as input, calculates the remainder by dividing the data by the divisor, and outputs the remainder. It also checks if the remainder is non-zero to detect any errors in the data. Key steps include appending zeros to the data, dividing bit-by-bit, storing the remainder, and checking if it is non-zero to detect errors.

Uploaded by

Aeydap
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

ROLL NO.

: 18CSR028

CN LAB /2020-21/ODD/A SECTION


ROLL NO.: 18CSR028
Ex.No. 6
: WRITE A PROGRAM TO IMPLEMENT CRC
Date : 07.12.20
20

Aim :

To implement CRC.

Coding :

#include <stdio.h>

#include <conio.h>

#include <string.h>

void main()

int i,j,keylen,msglen,flag=0;

char input[100], key[30],temp[30],quot[100],rem[30],key1[30];

printf("CYCLIC REDUNDANCY CHECK");

printf("\nEnter Data: ");

gets(input);

printf("\nEnter Divisior: ");

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++)

CN LAB /2020-21/ODD/A SECTION


ROLL NO.: 18CSR028
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 : ");

ROLL NO.: 18CSR023for(i=0;i<keylen-1;i++)

CN LAB /2020-21/ODD/A SECTION


ROLL NO.: 18CSR028
{

printf("%c",rem[i]);

for(i=0;i<keylen-1;i++)

if(rem[i]=='1')

flag=flag+1;

else

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]);

if(flag==0)

printf("\n There is NO ERROR");

else

printf("\n There is an ERROR");

getch();

CN LAB /2020-21/ODD/A SECTION


ROLL NO.: 18CSR028
}

Sample I/O:

Result:

The implementation of CRC has been verified.

CN LAB /2020-21/ODD/A SECTION

You might also like