/*----------------------------------------------------------------
NAME :GAURAV KHANDELWAL ROLL NO. :08BCE131
COLLAGE: NIRMA UNIVERSITY
AIM : TO IMPLEMENT CRC SENDER
-------------------------------------------------------------------*/
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<stdio.h>
char data[20];
char divisor[8],d_char[20];
int ans[100],ans1[100]={0},result[100]={0},frame,divisor1[8]={0};
int count=0,t=0;
void bin_conv(int s)
{
while(s!=0)
{
ans1[count]=s%2;
s/=2;
count++;
}
}
void parity_append(int a)
{
int z=0;
if(count%frame!=0)
{
z=1;
}
for(int i=0;i<count/frame+z;i++)
{
for(int j=0;j<frame;j++)
{
result[t]=ans[frame*i+j];
t++;
}
t=t+a;
}
}
void display(void)
{
for(int i=0;i<t;i++)
{
cout<<result[i];
}
}
void division(int a)
{
int z=0;
int temp[10];
if(count%frame!=0)
z=1;
for(int i=0;i<(count/frame)+z;i++)
{
for(int j=0;j<frame;j++)
{
if(j==0)
{
for(int q=0;q<a;q++)
temp[q]=result[(frame+a-1)*i+q];
}
else
{
for(int q=0;q<a-1;q++)
temp[q]=temp[q+1];
temp[q]=result[j+a-1+(frame+a-1)*i];
}
if(temp[0]==1)
{
for(int k=0;k<a;k++)
temp[k]=temp[k]^divisor1[k];
}
}
for(int l=0;l<a-1;l++)
result[(i*(a-1))+((i+1)*frame)+l]=temp[l+1];
}
}
void main()
{
clrscr();
cout<<"enter the data:";
gets(data);
cout<<"enter the frame size:";
cin>>frame;
cout<<"enter the error handler not more then 7:";
gets(divisor);
int i=0;
while(divisor[i]!='\0')
{
if(divisor[i]=='1')
divisor1[i]=1;
else
divisor1[i]=0;
i++;
}
int j=0,d,k;
while(data[j]!='\0')
{
d=toascii(data[j]);
d_char[j]=data[j];
bin_conv(d);
for(k=0;k<7;k++)
ans[7*j+k]=ans1[count-k-1];
j++;
}
parity_append(i-1);
cout<<"packet without parity:";
display();
division(i);
cout<<"\n";
cout<<"now packet with parit:";
display();
getch();
}
/*
If you want any program in c or c++ then mail me. I will provide you that progr
am.
For program mail me
[email protected],
[email protected] THANK YOU.
*/