Expt 5b - Implementation of Cyclic Redundance Check Using C-Program
Expt 5b - Implementation of Cyclic Redundance Check Using C-Program
Date: 14.06.23
AIM:
SOFTWARE USED:
PROCEDURE:
#include <stdio.h>
#include <string.h>
#define N strlen(gen_poly)
char data[28];
char check_value[28];
char gen_poly[10];
int data_length, i, j;
void XOR() {
for (j = 1; j < N; j++)
check_value[j] = ((check_value[j] ==
gen_poly[j]) ? '0' : '1');
}
void crc();
void receiver() {
printf("Enter the received data: ");
scanf("%s", data);
printf("\n-----------------------------\n");
printf("Data received: %s\n", data);
crc();
for (i = 0; (i < N - 1) && (check_value[i] != '1');
i++);
if (i < N - 1)
printf("\nError detected\n\n");
else
printf("\nNo error detected\n\n");
}
void crc() {
for (i = 0; i < N; i++)
check_value[i] = data[i];
do {
if (check_value[0] == '1')
XOR();
for (j = 0; j < N - 1; j++)
check_value[j] = check_value[j + 1];
check_value[j] = data[i++];
} while (i <= data_length + N - 1);
}
int main() {
printf("\nEnter data to be transmitted: ");
scanf("%s", data);
printf("\nEnter the Generating polynomial: ");
scanf("%s", gen_poly);
data_length = strlen(data);
for (i = data_length; i < data_length + N - 1; i++)
data[i] = '0';
printf("\n----------------------------------------");
printf("\nData padded with n-1 zeros: %s", data);
printf("\n----------------------------------------");
crc();
printf("\nCRC or Check value is: %s", check_value);
for (i = data_length; i < data_length + N - 1; i++)
data[i] = check_value[i - data_length];
printf("\n----------------------------------------");
printf("\nFinal data to be sent: %s", data);
printf("\n----------------------------------------\n");
receiver();
return 0;
}
A CRC is constructed to generate a 3 bit FCS for a 4-bit message. The generator pattern is
1011.
OUTPUT:
RESULT & INFERENCES:
Inference:
2. The code takes user input for the data to be transmitted and the
generating polynomial (1011) used for CRC calculations.
4. The receiver part of the code prompts the user to enter the received data.
It then performs CRC calculations on the received data and compares the
generated checksum (101) with the received checksum. In this case, the
received data matches the generated checksum, indicating that no errors
were detected during transmission.