You are on page 1of 17

GNIT Computer Networks

S Lab
PROGRAM 1:

(a)
AIM:To illustrate Bit Stuffing

PROGRAM:
#include<stdio.h
>
#include<conio.h
>
#include<string.h
> void main()
{
char
a[20],b1[20]="01111110",b2[20]="01111110",temp[20];
int count,i,j,k=0,t,c,n;
printf("enter
string\n");
scanf("%s",&a);
for(i=0;a[i]!='\0';i+
+)
{
count=0;
temp[k++]=a[i];
if(a[i]=='1')
{
for(j=i;j<(i+5);j++)
{
if(a[j]=='1')
GNIT Computer Networks
S Lab
{
count++;
}
}
if(count==5)
{
i=i+4;
for(t=0;t<4;t++)
{
temp[k+
+]='1';
}
temp[k++]='0';
}
}
}
temp[k]='\0';
printf("Stuffed output is %s
\n",temp); strcat(b1,temp);
strcat(b1,b2)
;
n=strlen(b1)
; k=0;
for(i=8;i<(n-8);i++)
{
temp[k++]=b1[i];
}
temp[k]='\0';
printf("The Stuffed string is
GNIT Computer Networks
S Lab
%s\n",temp); k=0;
for(i=0;temp[i]!='\0';i++)
{
count=0; a[k+
+]=temp[i];
if(temp[i]=='1')
GNIT Computer Networks
S Lab
{
for(j=i;j<(i+5);j++)
{
if(temp[j]=='1')
{
count++;
}
}
if(count==5)
{
i=i+5;
for(t=0;t<4;t++)
{
a[k++]='1';
}
}
}
}
a[k]='\0';
printf("Destuffed string is
%s\n",a); getch();
}

Execution:
INPUT:
Enter the String :
11111100111 OUTPUT:
Stuffed output is
111110100111
GNIT Computer Networks
S Lab
Delimited String is
0111111011111010011101111110 Destuffed
String is 11111100111
GNIT Computer Networks
S Lab
(b)
AIM: To illustrate character stuffing

PROGRAM:
#include<stdio.h
>
#include<conio.h
>
#include<string.h
> void main()
{
char a[50],b[50],s[100],d[50];
int I,j,c;
clrscr();
printf(“enter the
string\n”);
scanf(“%s”,a);
i=0,j=0;
while(a[i]!=’\0’)
{
c=0;
b[j]=a[i];
if(a[i]==’e’)
{
if(a[i-1]==’l’ && a[i-
2]==’d’) c=1;
}
if(c==1)
{
GNIT Computer Networks
S Lab
b[++j]=’d’;
GNIT Computer Networks
S Lab
b[++j]=’l’;
b[++j]=’e’;
}
i+
+;
j+
+;
}
b[j]=’\0’;
sprintf(s,”%s %s “,”dle stx”,b,”dle
etx”); printf(“character stuffed ”,\n
%s \n”,s); i=5,j=0;
while(s[i+8]!=’\0’)
{
c=0;
d[j]=s[j];
if(s[i]==’e’)
{
if(s[i-1]==’l’ && s[i-2]==’d’)
{
c=1;
}
if(c==1)
i+=3;
i+
+;
j+
+;
}
GNIT Computer Networks
S Lab
d[j]=’\0’;
printf(“destuffed string :\n %s
\n”,d); getch();
}

Execution:

Case 1:
INPUT:
Enter the string : welcomedle
OUTPUT:
Character stuffed: dle stx welcomedle dle etx
Destuffed string : welcomedle

Case 2:
INPUT:
Enter the string:data dle data
OUTPUT:
Character stuffed:dlestx datadledata dle dleetx
Destuffed string : data dle data
PROGRAM 2:

AIM: To implement on a data set of characters using the


three CRC polynomials- CRC 12,CRC 16 and CRC CCIP

PROGRAM:
#include<stdio.h
>
#include<conio.
h> void main()
{
int n,m,i,f=0,d[20],dr[20],r[20];
void func(int d[],int n,int dr[],int
m); clrscr();
printf("\n Enter the length of the
polynomial:"); scanf("%d",&m);
printf("\n Enter the
polynomial:"); for(i=0;i<m;i+
+)
{
scanf("%d",&dr[i]);
}
printf("\n Enter the length of the data
word:"); scanf("%d",&n);
printf("\n Enter data
word:"); for(i=0;i<n;i++)
{
scanf("%d",&d[i]);
r[i]=d[i];
}
for(i=n;i<(n+m-1);i++)
d[i]=0;
func(d,n,dr,m);
printf("CRC:\n");
for(i=n;i<(n+m-1);i++)
{
printf("%d",d[i]);
r[i]=d[i];
}
printf("\n Result of data
word: "); for(i=0;i<(n+m-
1);i++)
printf("%d",r[i]);
printf("\n Enter reciever data word:
"); for(i=0;i<(n+m-1);i++)
scanf("%d",&d[i]);
func(d,n,dr,m);
printf("\n Final result is:
"); for(i=n;i<(n+m-
1);i++)
{
printf("%d",d[i]);
if(d[i]!=0)
f=1;
}
if(f==0)
printf("\n data accepted");
else
printf("\n data rejected");
getch();
}
void func(int d[],int n,int dr[],int m)
{
int i,j,k;
for(i=0;i<n;i++)
{
if(d[i]==1)
{
for(j=0,k=i;j<m;j++,k++)
{
if(d[k]==dr[j])
d[k]=0;
else
d[k]=1;
}
}
}
}
Execution:

Case 1: (for CRC12)

Input:
Enter the length of the polynomial:
13 Enter the polynomial:
1100000001111 Enter the length
of data word: 4
Enter the data word:
1001

OUTPUT:
CRC:
000001011010
Result of data word :
1001001001011010 Final Result :
000000001001
Data rejected

Case2: (for simple polynomial)


Enter the length of the
polynomial: 4 Enter the
polynomial: 1110
Enter the length of data
word: 2 Enter the data
word: 11
CRC:
100
Result of data word:
11100 Final Result: 000
Data accepted

You might also like