0% found this document useful (0 votes)
17 views9 pages

Experiment-4 Aim:-: Exp No: Date: Page No

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)
17 views9 pages

Experiment-4 Aim:-: Exp No: Date: Page No

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/ 9

Exp No: Page No:

Date:
Experiment-4

Aim:- Write a Program to implement on a data set of characters the three CRC polynomials –
CRC 12, CRC 16 and CRC CCIP.

Description:- The Cyclic Redundancy Check algorithm checks for errors and verifies the
accuracy of the data delivered by the sender. CRC requires a generator polynomial in order to
compute the check value using binary division in addition to the data that has to be transferred.
To ensure that the data is genuine, the check value or CRC is sent with it to the
recipient. The degree of the polynomial can be used as the bit locations to
represent the data that will be conveyed to the recipient in polynomial form. The binary data
1010101 of length 7 can be, for instance, represented as, x7+x5+x3+1 As the value of that
representation is also 0, the bit value of 0 is not represented. The following are the CRC's
steps: the sender's side,

o The generating polynomial of length l and the data of length n are ready.

o The data that has to be delivered has (l-1) zeros attached to it.

o The binary version of the generating polynomial is used as the divisor in binary
division, with the data acting as the dividend. The check value is the remainder of the
binary division.

o The check value is added to the end of the data before sending the signal.

Check value, or CRC, is represented mathematically as,

The n in this case refers to the generator polynomial's number of bits. Towards the receiver,

o The received data is divided once again using binary operations, with the data serving
as the dividend and the generating polynomial's binary counterpart serving as the
divisor.

o The data sent from the sender is error-free if the binary division's residual is zero. If
the residual does not equal zero, an error has tainted the signal.

Algorithm

The CRC program's implementation algorithm is as follows:

o Get the data and the polynomial generator.

o Let n represent the generator polynomial's length.

o Add n-1 zeros after the data.

ADITYA ENGINEERING COLLEGE(A) Roll No: 22A91A6151


Exp No: Page No:
Date:
o Invoke the CRC function.

The CRC function's algorithm is as follows:

o Get the data's first n bits.

o If the first bit is 1, then combine the generator polynomial with the first n bits of the
data in a XOR operation.

o To retain the first bit, move the bits one place.

o Add a little portion of the data. Continue until all of the data's bits have been inserted.

Program:-

#define N strlen(g)

#include <stdio.h>

#include <string.h>

char t[28],cs[28],g[28];

int a;

int e;

int c;

int b;

voidxor()

for(c=1;c<N;c++)

cs[c]=((cs[c]==g[c])?'0':'1');

void crc()

for(e=0;e<N;e++)

cs[e]=t[e];

ADITYA ENGINEERING COLLEGE(A) Roll No: 22A91A6151


Exp No: Page No:
Date:
do

if(cs[0]=='1')

voidxor();

for(c=0;c<N-1;c++)

cs[c]=cs[c+1];

cs[c]=t[e++];

}while(e<=a+N-1);

int main()

int flag=0;

do{

printf("\n1.crc12\n2.crc16\ncrc ccit\n4.exit\n\nEnter your option.");

scanf("%d",&b);

switch(b)

case 1:strcpy(g,"1100000001111");

break;

case 2:strcpy(g,"11000000000000101");

break;

case 3:strcpy(g,"10001000000100001");

break;

case 4:return 0;

ADITYA ENGINEERING COLLEGE(A) Roll No: 22A91A6151


Exp No: Page No:
Date:
}

printf("\n enter data:");

scanf("%s",t);

printf("\n \n");

printf("\n generating polynomial:%s",g);

a=strlen(t);

for(e=a;e<a+N-1;e++)

t[e]='0';

printf("\n \n");

printf("mod-ified data is:%s",t);

printf("\n \n");

crc();

printf("checksum is:%s",cs);

for(e=a;e<a+N-1;e++)

t[e]=cs[e-a];

printf("\n \n");

printf("\n final codeword is : %s",t);

printf("\n \n");

printf("\ntest error detection 0(yes) 1(no)?:");

scanf("%d",&e);

if(e==0)

do{

printf("\n\tenter the position where error is to be inserted:");

scanf("%d",&e);

ADITYA ENGINEERING COLLEGE(A) Roll No: 22A91A6151


Exp No: Page No:
Date:
}

while(e==0||e>a+N-1);

t[e-1]=(t[e-1]=='0')?'1':'0';

printf("\n \n");

printf("\n\terroneous data:%s\n",t);

crc();

for(e=0;(e<N-1)&&(cs[e]!='1');e++);

if(e<N-1)

printf("error detected\n\n");

else

printf("\n no error detected \n\n");

printf("\n ");

}while(flag!=1);

ADITYA ENGINEERING COLLEGE(A) Roll No: 22A91A6151


Exp No: Page No:
Date:
Output:-

ADITYA ENGINEERING COLLEGE(A) Roll No: 22A91A6151


Exp No: Page No:
Date:

ADITYA ENGINEERING COLLEGE(A) Roll No: 22A91A6151


Exp No: Page No:
Date:

ADITYA ENGINEERING COLLEGE(A) Roll No: 22A91A6151


Exp No: Page No:
Date:

ADITYA ENGINEERING COLLEGE(A) Roll No: 22A91A6151

You might also like