Professional Documents
Culture Documents
Os Assignment
Os Assignment
DATA COMMUNICATIONS
GROUP ASSIGNMENT
on
“CRC using C++”
BACHELOR OF ENGINEERING
IN
COMPUTER SCEINCE AND ENGINEERING
submitted by
ANNA MARIAM CHACKO 1SI16CS016
BHUVANAPALLI ADITYA PRANAV 1SI16CS026
BOMMANAPALLI VIJAYA MADVESH 1SI16CS027
CRC Program:
#include <iostream>
using namespace std;
string divisor= "10001000000100001";
string sender(string dataword,string divisor)
{
int i,j,k;
string augdataword,remainder,subtrahend,codeword;
augdataword=dataword;
for(i=0;i<divisor.length()-1;i++)
{
augdataword.append("0");
}
cout<<"Augmented Data word = "<<augdataword<<endl;
remainder=augdataword;
for(i=0;i<augdataword.length()-divisor.length()+1;i++)
{
k=i;
switch(remainder[i])
{
case '1':subtrahend=divisor;break;
case '0':subtrahend=divisor;
for(j=0;j<divisor.length();j++)
{
subtrahend[j]='0';
}
break;
}
for(j=0;j<subtrahend.length();j++)
{
if(remainder[k]==subtrahend[j])
{
remainder[k++]='0';
}
else
{
remainder[k++]='1';
}
}
}
cout<<"Remainder = "<<remainder<<endl;
codeword=remainder;
for(i=0;i<augdataword.length();i++)
{
if(augdataword[i]==remainder[i])
{
codeword[i]='0';
}
else
{
codeword[i]='1';
}
}
codeword[i]='\0';
cout<<"Code Word = "<<codeword<<endl;
return codeword;
}
bool receiver(string receivedcode,string divisor)
{
int i,j,k;
string remainder,subtrahend,dataword;
cout<<"Received Code = "<<receivedcode<<endl;
remainder=receivedcode;
for(i=0;i<receivedcode.length()-divisor.length()+1;i++)
{
k=i;
switch(remainder[i])
{
case '1':subtrahend=divisor;break;
case '0':subtrahend=divisor;
for(j=0;j<divisor.length();j++)
{
subtrahend[j]='0';
}
break;
}
for(j=0;j<subtrahend.length();j++)
{
if(remainder[k]==subtrahend[j])
{
remainder[k++]='0';
}
else
{
remainder[k++]='1';
}
}
}
dataword=receivedcode.substr(0,receivedcode.length()-divisor.length()+1);
cout<<"*******Received Data Word = \""<<dataword<<"\"*******"<<endl;
cout<<"Remainder = "<<remainder<<endl;
for(i=0;i<remainder.length();i++)
{
if(remainder[i]=='1')
return false;
}
return true;
}
int main()
{
string msg,receivedcodeword,codeword;
cout<<"Divisor for CRC16="<<divisor<<endl;
OUTPUT:
Output1:
Divisor for CRC16=10001000000100001
Enter Sent Message : 1001
Augmented Data word = 10010000000000000000
Remainder = 00001001000100101001
Code Word = 10011001000100101001
Enter Received Code word : 10011001000100101001
Received Code = 10011001000100101001
*******Received Data Word = "1001"*******
Remainder = 00000000000000000000
Correct message sent
Output2:
Divisor for CRC16=10001000000100001
Enter Sent Message : 1001
Augmented Data word = 10010000000000000000
Remainder = 00001001000100101001
Code Word = 10011001000100101001
Enter Received Code word : 10011001000100101000
Received Code = 10011001000100101000
*******Received Data Word = "1001"*******
Remainder = 00000000000000000001
Discard the message