0% found this document useful (0 votes)
27 views3 pages

Solution CRC

Uploaded by

Subh Das
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)
27 views3 pages

Solution CRC

Uploaded by

Subh Das
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/ 3

Networking Lab

(PCC-CS-692)

Solution for Assignment for Cyclic Redundancy Check(CRC)

1. Write a C code to encode a user provided dataword using CRC procedure.

Test Case 1:

Input:
Dataword: 100100
Coefficients of generator polynomial: 1101

Output:
Updated divident: 100100000
The codeword is: 100100001

Test Case 2:

Input:
Dataword : 1010001101
Coefficients of generator polynomial: 110101

Output:
Updated divident: 101000110100000
The codeword is: 101000110101110

#include<stdio.h>
#include<string.h>
void main()
{
char data[50],divisor[10],data1[50];
int dl,divl,i,j;
printf("\nEnter the input data: ");
gets(data);
printf("\nEnter coefficients of generator polynomial: ");
gets(divisor);
dl=strlen(data);
divl=strlen(divisor);
for(i=0;i<divl-1;i++) //no of 0's that have to add with divident
data[dl+i]='0';
data[dl+i]='\0';
printf("\nUpdated divident: %s",data);
strcpy(data1,data);
for(i=0;i<dl;i++)
{
if(data1[i]=='1')
{
for(j=0;j<divl;j++)
{
if(data1[i+j]==divisor[j])
data1[i+j]='0';
else
data1[i+j]='1';
}
}
}
for(i=dl;i<dl+(divl-1);i++)
data[i]=data1[i];
printf("\nThe codeword is: %s",data);
}

2. Write a C code to decode a user provided codeword using CRC procedure.


Provide the output along with original data (good/bad).

Test Case 1:
Input:
Codeword:101000110101110
Coefficients of generator polynomial:110101

Output:
Original data receive
Actual data: 1 0 1 0 0 0 1 1 0 1

Test Case 2:
Input:
Codeword: 100100001
Coefficients of generator polynomial: 1101

Output:

Original data receive


Actual data: 1 0 0 1 0 0
#include <stdio.h>
#include <string.h>
void main()
{
int dl,divl,i,j;
char div[50],data[50],data1[50];
printf("\nEnter the codeword:");
scanf("%s",data);
dl=strlen(data);
printf("\nEnter coefficients of generator polynomial:");
scanf("%s",div);
divl=strlen(div);
strcpy(data1,data);
for(i=0;i<dl-(divl-1);i++)
{
if(data[i]=='1')
{
for(j=0;j<divl;j++)
{
if(data[i+j]==div[j])
data[i+j]='0';
else
data[i+j]='1';
}
}
}
j=0;
for(i=dl-(divl-1);i<dl;i++)
j=j+data[i]-48;
if(j==0)
{
printf("\nOriginal data receive\n");
printf("\n Actual data : ");
for(i=0;i<dl-(divl-1);i++)
printf("%c ",data1[i]);
}
else
printf("\n data recv wrong \n");
}

You might also like