0% found this document useful (0 votes)
314 views4 pages

Program - 3: AIM: Write A C Program To Implement Cyclic Redundant Check

The document describes a C program to implement cyclic redundancy check (CRC) for detecting errors in digital data transmission. The CRC algorithm appends check bits called a checksum to the message being transmitted. The receiver divides the received data by the same generator polynomial used by the sender to calculate the checksum. If the remainder is all zeros, the message was received without errors. Otherwise, an error occurred in transmission and the receiver sends a negative acknowledgment to request retransmission. The program code defines functions to calculate the CRC checksum and check the received message for errors. It prompts the user for input, performs CRC calculations, and outputs whether the message was received correctly or with errors.

Uploaded by

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

Program - 3: AIM: Write A C Program To Implement Cyclic Redundant Check

The document describes a C program to implement cyclic redundancy check (CRC) for detecting errors in digital data transmission. The CRC algorithm appends check bits called a checksum to the message being transmitted. The receiver divides the received data by the same generator polynomial used by the sender to calculate the checksum. If the remainder is all zeros, the message was received without errors. Otherwise, an error occurred in transmission and the receiver sends a negative acknowledgment to request retransmission. The program code defines functions to calculate the CRC checksum and check the received message for errors. It prompts the user for input, performs CRC calculations, and outputs whether the message was received correctly or with errors.

Uploaded by

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

LAB CYCLE-1 Date:08-03-13

PROGRAM -3

AIM: Write a c program to implement Cyclic Redundant Check

DESCRIPTION:

The cyclic redundancy check, or CRC, is a technique for detecting errors in digital data, but not
for making corrections when errors are detected. It is used primarily in data transmission. In the CRC
method, a certain number of check bits, often called a checksum, are appended to the message being
transmitted. The receiver can determine whether or not the check bits agree with the data, to ascertain
with a certain degree of probability whether or not an error occurred in transmission. If an error occurred,
the receiver sends a “negative acknowledgement” (NAK) back to the sender, requesting that the message
be retransmitted.

THE ALGORITHM FOR COMPUTING THE CHECKSUM IS AS FOLLOWS:


1. Let r be the degree of G(x)(generator) and m be no: of bits in the dataword. Append r zero bits (i.e. if
generator contains n no: of bits then add n-1 bits) to the low-order end of the frame so it now contains m
+ r bits
2. Divide the bit string corresponding to G(x)(divisor) into the bit string corresponding to new(m + r)
bits, using modulo 2 division(i.e. use xor operation).
3. Remainder will be appended to original dataword and the sender sends this to the receiver.
4. Both sender and receiver agree on common divisor i.e. g(x).
5. When the receiver receives the data it checks the data exactly done by the sender i.e. it divides the
transmitted data by the divisor and does xor operation
6. At receiver side the reminder is all 0’s then transmitted data is error free otherwise there is error in
transmitted data.
5. If there is error the receiver sends negative acknowledgement to sender and sender retransmits the data

Consider below example:

Fig-2 Calculation of the polynomial code checksum


PROGRAM

#include <stdio.h>

Dept of CSE, K L UNIVERSITY 6 Reg no-12203008


LAB CYCLE-1 Date:08-03-13

#include <stdlib.h>
void crcfunc(int[],int[]);
int len1,len,len2;
int res[30],l=0;
int main()
{
int m[30],g[10];
int i,j;
int rm[30];
printf("\nEnter the length of message:");
scanf("%d",&len1);
printf("\nEnter the message:");
for(i=0;i<len1;i++)
{
scanf("%d",&m[i]);
res[i]=m[i];
}
printf("\nEnter the length of generator:");
scanf("%d",&len2);
len=len1+len2-1;
printf("\nEnter the generator:");
for(i=0;i<len2;i++)
scanf("%d",&g[i]);
for(i=len1;i<len;i++)
m[i]=0;
crcfunc(m,g);
printf("\nMessage to be transmitted:");
for(i=0;i<len;i++)
printf("%d ",res[i]);
printf("\nEnter the received message");
for(i=0;i<len;i++)
scanf("%d",&rm[i]);
crcfunc(rm,g);

for(i=len1;i<len;i++)
{
if(res[i]==0)
l=1;
else
{
l=0;
break;
}
}
if(l==1)
printf("\nMessage received without errors");
else
printf("\nMessage received with errors");
return 0;
}
void crcfunc(int m[],int g[])

Dept of CSE, K L UNIVERSITY 7 Reg no-12203008


LAB CYCLE-1 Date:08-03-13

{
int tem[len1];
int i,j,c,k=0;
do
{
c=0;
for(j=0,i=k;j<len2&&i<(len);i++,j++)
{
m[i]=m[i]^g[j];
tem[j]=m[i];
}
for(j=0;j<(len1+len2-1);j++)
{
if(tem[j]==0)
{
k++;
c++;
}
else
break;
}
}while(c<=(len-i));
for(i=len,j=len;j>=len1;j--,i--)
res[j]=m[i];
printf("CRC -");
for(i=len1;i<len;i++)
printf("%d",res[i]);
}

OUTPUT 1:

Enter the length of message: 12

Enter the message: 1 0 1 0 1 1 0 1 1 0 1 0

Enter the length of generator:5

Enter the generator:1 0 1 1 1

CRC -1011

Message to be transmitted:1 0 1 0 1 1 0 1 1 0 1 0 1 0 1 1

Enter the received message1 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0

CRC -0100

Message received with errors

OUTPUT 2:

Dept of CSE, K L UNIVERSITY 8 Reg no-12203008


LAB CYCLE-1 Date:08-03-13

Enter the length of message:10

Enter the message:1 1 0 1 0 1 1 0 1 1

Enter the length of generator:5

Enter the generator:1 0 0 1 1

CRC -1110

Message to be transmitted:1 1 0 1 0 1 1 0 1 1 1 1 1 0

Enter the received message1 1 0 1 0 1 1 0 1 1 1 1 1 0

CRC -0000

Message received without errors

Dept of CSE, K L UNIVERSITY 9 Reg no-12203008

You might also like