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

Computer Networks (Cs8591) Assignment 2: P.Vishnu Priya 311518104053 Iii Be-Cse

This C program implements a cyclic redundancy check (CRC) for error detection in data transmission. It takes in a message, divisor, and number of bits as input from the sender. It appends zeros to the message and performs a CRC to generate a remainder. The codeword consisting of the message and remainder is transmitted. At the receiver, it performs CRC on the received codeword and checks if the remainder is non-zero to detect any errors during transmission.

Uploaded by

vishnu
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)
52 views4 pages

Computer Networks (Cs8591) Assignment 2: P.Vishnu Priya 311518104053 Iii Be-Cse

This C program implements a cyclic redundancy check (CRC) for error detection in data transmission. It takes in a message, divisor, and number of bits as input from the sender. It appends zeros to the message and performs a CRC to generate a remainder. The codeword consisting of the message and remainder is transmitted. At the receiver, it performs CRC on the received codeword and checks if the remainder is non-zero to detect any errors during transmission.

Uploaded by

vishnu
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

P.

VISHNU PRIYA

311518104053

III BE-CSE

COMPUTER NETWORKS(CS8591)

ASSIGNMENT 2

PROGRAM FOR CYCLIC REDUNDANCY CHECK

PROGRAM:

#include <stdio.h>
#include <conio.h>
void cyclic(int c[20], int b[20], int n, int div) {
int i, j, k;
for (i = 0; i<n; i++) {
if (b[0] == c[i]) {
for (k = i, j = 0; j<div + 1; k++, j++) {
if (!(c[k] ^ b[j]))
c[k] = 0;
else
c[k] = 1;
}
}
}
}
int main() {
int i, n, div, a[20], b[20], c[20];
printf("\t CYCLIC REDUNDANCY CHECK AND ERROR DETECTION");
printf("\n\n-------SENDER SIDE--------\n");
printf("\n");
printf("\nENTER THE NUMBER OF MESSAGE BITS : ");
scanf("%d", &n);
printf("\nENTER THE MESSAGE : ");
for (i = 0; i<n; i++)
scanf("%d", &a[i]);
printf("\nENTER THE NUMBER OF DIVISOR BITS : ");
scanf("%d", &div);
printf("\nENTER THE DIVISOR : ");
for (i = 0; i<div; i++)
scanf("%d", &b[i]);
div--;
for (i = 0; i<div; i++)
a[n + i] = 0;
for (i = 0; i<n + div; i++)
c[i] = a[i];
cyclic(c, b, n, div);
printf("\n THE REMAINDER IS : ");
for (i = 0; i<div; i++) {
printf("%d", c[n + i]);
a[n + i] = c[n + i];
}
printf("\nTHE TRANSMITTED CODEWORD IS : ");
for (i = 0; i<n + div; i++)
printf("%d", a[i]);
printf("\n");
printf("\n------RECEIVER SIDE-------");
printf("\n\nCODEWORD RECEIVED : ");
for (i = 0; i<n + div; i++)
scanf("%d", &a[i]);
for (i = 0;i<n + div;i++)
c[i] = a[i];
cyclic(c, b, n, div);
printf("\n REMAINDER : ");
for (i = 0; i<div; i++) {
printf("%d", c[n + i]);
a[n + i] = c[n + i];
}
for (i = 0; i<div; i++) {
if (c[n + i]) {
printf("\nTRANSMISSION IS NOT DONE
SUCCESSFULLY\nDATAWORD IS DISCARDED\n");
getch();
return 0;
}
}
printf("\n TRANSMISSION IS DONE SUCCESSFULLY\n");
printf(" THE RECEIVED MESSAGE IS : ");
for (i = 0; i<n; i++)
printf("%d", a[i]);
getch();
return 0;
}
OUTPUT:

You might also like