//this code is designed by codenation.
//6:05 12/20/2020
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
int i,j,keylen,msglen;
char data[100], generator[30],temp[30],quot[100],rem[30],generator1[30];
printf("Enter Data to send: ");
scanf("%[^\n]",&data);
printf("Enter generator polynomial: ");
scanf(" %[^\n]",&generator);
keylen=strlen(generator);
msglen=strlen(data);
strcpy(generator1,generator);
for(i=0;i<keylen-1;i++)
{
data[msglen+i]='0';
}
for(i=0;i<keylen;i++)
{
temp[i]=data[i];
}
for(i=0;i<msglen;i++)
{
quot[i]=temp[0];
if(quot[i]=='0')
{
for(j=0;j<keylen;j++)
{
generator[j]='0';
}
}
else
{
for(j=0;j<keylen;j++)
{
generator[j]=generator1[j];
}
}
for(j=keylen-1;j>0;j--)
{
if(temp[j]==generator[j])
rem[j-1]='0';
else
rem[j-1]='1';
}
rem[keylen-1]=data[i+keylen];
strcpy(temp,rem);
}
strcpy(rem,temp);
printf("\nQuotient is :\n");
for(i=0;i<msglen;i++)
{
printf("%c",quot[i]);
}
printf("\nRemainder is :\n");
for(i=0;i<keylen-1;i++)
{
printf("%c",rem[i]);
}
printf("\nthe data for transmission is :\n");
for(i=0;i<msglen;i++)
{
printf("%c",data[i]);
}
for(i=0;i<keylen-1;i++)
{
printf("%c",rem[i]);
}
return 0;
}
//this code is developed by codenation.
Comments
Post a Comment