Computer Networks Lab Manual R18
Computer Networks Lab Manual R18
LAB MANUAL
III-B.TECH I-SEM
JNTUH-R18
Faculty In-charge:
COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING
………………………………………………………
000000000000000000000000000000000000000
000000000000000000000000000000000000000
00000000000000000000000000000.A.SATISH,
Asst.Prof.
DEPARTMENT OF
COMPUTER SCIENCE ANDENGINEERING
LIST OF EXPERIMENTS:
1. Implement the data link layer framing methods such as character, character
stuffing,and bit stuffing.
2. Implement on a data set of characters the three CRC polynomials – CRC 12,
CRC 16 and CRC CCIP .
4. Take an example subnet graph with weights indicating delay between nodes.
Now obtain Routing table art each node using distance vector routing algorithm
6. Take a 64 bit playing text and encrypt the same using DES algorithm.
8. Using RSA algorithm encrypts a text data and Decrypt the same.
Course Objectives:
Course Outcomes:
.
Ability to configure the routing table
GENERAL INSTRUCTIONS
1. Students are instructed to come to laboratory on time. Late comers are not entertained
in the lab.
1. Students should be punctual to the lab. If not, the conducted experiments will not be repeated.
2. Students are expected to come prepared at home with the experiments which are going to be
performed.
3. Students are instructed to display their identity cards before entering into the lab.
5. Any damage/loss of system parts like keyboard, mouse during the lab session,
it is student’s responsibility and penalty or fine will be collected from the student.
2. Students should update the records and lab observation books session wise. Before
leaving the lab the student should get his lab observation book signed by the faculty.
3. Students should submit the lab records by the next lab to the concerned faculty members
in the staffroom for their correction and return.
4. Students should not move around the lab during the lab session.
5. If any emergency arises, the student should take the permission from faculty
member concerned in written format.
6. The faculty members may suspend any student from the lab session on disciplinary grounds.
Program:
#include <stdio.h>
#include <conio.h>
#include <string.h>
main()
{
int a[15];
int i,j,k,n,c=0,pos=0;
clrscr();
printf("\n Enter the number of bits");
scanf("%d",&n);
printf("\n Enter the bits");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
if(a[i]==1)
{
c++;
if(c==5)
{
pos=i+1;
c=0;
for(j=n;j>=pos;j--)
{
k=j+1;
a[k]=a[j];
}
a[pos]=0;
n=n+1;
}
}
else
c=0;
}
for(i=0;i<n;i++)
{
printf("%d",a[i]);
}
printf(" 01111110 ");
getch();
}
Output:
#include <stdio.h>
#include <conio.h>
#include <string.h>
void charc(void);
void main()
{
int choice;
while(1)
{
printf("\n\n\n1.character stuffing");
printf("\n\n2.exit");
printf("\n\n\nenter choice");
scanf("%d",&choice);
printf("%d",choice);
if(choice>2)
printf("\n\n invalid option....please renter");
switch(choice)
{
case 1:
charc();
break;
}
void charc(void)
{
char c[50],d[50],t[50];
int i,m,j;
clrscr();
printf("enter the number of characters\n");
scanf("%d",&m);
printf("\n enter the characters\n");
for(i=0;i<m+1;i++)
{
scanf("%c",&c[i]);
}
printf("\n original data\n");
for(i=0;i<m+1;i++)
printf("%c",c[i]);
d[0]='d';
d[1]='l';
d[2]='e';
d[3]='s';
d[4]='t';
d[5]='x';
for(i=0,j=6;i<m+1;i++,j++)
{
if((c[i]=='d'&&c[i+1]=='l'&& c[i+2]=='e'))
{
d[j]='d';
j++;
d[j]='l';
j++;
d[j]='e';
j++;
m=m+3;
}
d[j]=c[i];
}
m=m+6;
m++;
d[m]='d';
m++;
d[m]='l';
m++;
d[m]='e';
m++;
d[m]='e';
m++;
d[m]='t';
m++;
d[m]='x';
m++;
printf("\n\n transmitted data: \n");
for(i=0;i<m;i++)
{
printf("%c",d[i]);
}
for(i=6,j=0;i<m-6;i++,j++)
{
if(d[i]=='d'&&d[i+1]=='l'&&d[i+2]=='e'&&d[i+3]=='d'&&d[i+4]=='l'&&d[i+5]=='e')
i=i+3;
t[j]=d[i];
}
printf("\n\nreceived data:");
for(i=0;i<j;i++)
{printf("%c",t[i]);
}
}
Output:
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
int i,j,keylen,msglen;
char input[100], key[30],temp[30],quot[100],rem[30],key1[30];
clrscr();
printf("Enter Data: ");
gets(input);
printf("Enter Key: ");
gets(key);
keylen=strlen(key);
msglen=strlen(input);
strcpy(key1,key);
for(i=0;i<keylen-1;i++)
{
input[msglen+i]='0';
}
for(i=0;i<keylen;i++)
temp[i]=input[i];
for(i=0;i<msglen;i++)
{
quot[i]=temp[0];
if(quot[i]=='0')
for(j=0;j<keylen;j++)
key[j]='0';
else
for(j=0;j<keylen;j++)
key[j]=key1[j];
for(j=keylen-1;j>0;j--)
{
if(temp[j]==key[j])
rem[j-1]='0';
else
rem[j-1]='1';
}
rem[keylen-1]=input[i+keylen];
strcpy(temp,rem);
}
strcpy(rem,temp);
printf("\nQuotient is ");
for(i=0;i<msglen;i++)
printf("%c",quot[i]);
printf("\nRemainder is ");
for(i=0;i<keylen-1;i++)
printf("%c",rem[i]);
printf("\nFinal data is: ");
for(i=0;i<msglen;i++)
printf("%c",input[i]);
for(i=0;i<keylen-1;i++)
printf("%c",rem[i]);
getch();
}
Output:
enter data:1101011011
enter key:10011
quotient is 1100001010
remainder is 1110
final data is:1101011011 1110
#include<stdio.h>
#include<conio.h>
#define INFINITY 9999
#define MAX 10
void dijkstra(int G[MAX][MAX],int n,int startnode);
int main()
{
int G[MAX][MAX],i,j,n,u;
printf("Enter no. of vertices:");
scanf("%d",&n);
printf("\nEnter the adjacency matrix:\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&G[i][j]);
return 0;
}
void dijkstra(int G[MAX][MAX],int n,int startnode)
{
int cost[MAX][MAX],distance[MAX],pred[MAX];
int visited[MAX],count,mindistance,nextnode,i,j;
while(count<n-1)
{
mindistance=INFINITY;
nextnode=i;
}
j=i;
do
{
j=pred[j];
printf("<-%d",j);
}while(j!=startnode);
}
}
Output:
Program:
#include<stdio.h>
struct node
{
unsigned dist[20];
unsigned from[20];
}rt[10];
int main()
{
int costmat[20][20];
int nodes,i,j,k,count=0;
printf("\nEnter the number of nodes : ");
scanf("%d",&nodes);//Enter the nodes
printf("\nEnter the cost matrix :\n");
for(i=0;i<nodes;i++)
{
for(j=0;j<nodes;j++)
{
scanf("%d",&costmat[i][j]);
costmat[i][i]=0;
rt[i].dist[j]=costmat[i][j];//initialise the distance equal to cost matrix
rt[i].from[j]=j;
}
}
do
{
count=0;
for(i=0;i<nodes;i++)//We choose arbitary vertex k and we calculate the
direct distance from the node i to k using the cost matrix
//and add the distance from k to node j
for(j=0;j<nodes;j++)
for(k=0;k<nodes;k++)
if(rt[i].dist[j]>costmat[i][k]+rt[k].dist[j])
{//We calculate the minimum distance
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];
rt[i].from[j]=k;
count++;
}
}while(count!=0);
for(i=0;i<nodes;i++)
{
printf("\n\n For router %d\n",i+1);
for(j=0;j<nodes;j++)
{
printf("\t\nnode %d via %d Distance %d ",j+1,rt[i].from[j]
+1,rt[i].dist[j]);
}
}
printf("\n\n");
getch();
}
Output:
Enter the number of nodes :
3
Enter the cost matrix :
027
201
710
For router 1
node 1 via 1 Distance 0
node 2 via 2 Distance 2
node 3 via 3 Distance 3
For router 2
node 1 via 1 Distance 2
node 2 via 2 Distance 0
node 3 via 3 Distance 1
For router 3
node 1 via 1 Distance 3
node 2 via 2 Distance 1
node 3 via 3 Distance 0
Output:
Output:
6. Take a 64 bit playing text and encrypt the same using DES algorithm.
AIM: Take a 64 bit playing text and encrypt the same using DES
algorithm.
Program:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
void main ()
clrscr ();
while(1)
printf("\n-----MENU-----\n");
scanf ("%d",&ch);
switch (ch)
Case 1:
printf("\data Encryption");
fflush (stdin);
gets (plain);
gets (key);
lp=strlen(key);
for (i=0;plain[i]!='\0';i++)
cipher[i]=plain[i]^lp;cipher[i]='\0';
Puts (cipher);
break;
case 2:
printf("\nData decryption");
for(i=0;cipher[i]!='\0';i++)
plain[i]=cipher[i]^lp;
puts (plain);
break;
case 3:
Exit (0);
getch ();
OUT PUT:
--------- MENU--------
1: Data Encryption
2: Data Decryption
3: Exit
Data Encryption
--------- MENU--------
1: Data Encryption
2: Data Decryption
KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 56
COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING
3: Exit
Data Decryption
--------- MENU--------
1: Data Encryption
2: Data Decryption
3: Exit
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
main()
{
char pwd[20];
char alpha[26]="abcdefghijklmnopqrstuvwxyz";
int num[20],i,n,key;
clrscr();
printf("\nEnter the password:");
scanf("%s",&pwd);
n=strlen(pwd);
for(i=0;i<n;i++)
num[i]=toascii(tolower(pwd[i]))-'a';
printf("\nEnter the key:");
scanf("%d",&key);
for(i=0;i<n;i++)
num[i]=(num[i]+key)%26;
for(i=0;i<n;i++)
pwd[i]=alpha[num[i]];
printf("\nThe key is:%d",key);
printf("\nEncrypted text is:%s",pwd);
for(i=0;i<n;i++){num[i]=(num[i]-key)%26;
if(num[i]<0)num[i]=26+num[i];
pwd[i]=alpha[num[i]];
}
printf("\nDecrypted text is:%s",pwd);
getch();
}
Output:
8. Using RSA algorithm encrypts a text data and Decrypt the same.
AIM: Using RSA algorithm encrypts a text data and Decrypt the same
Program:
#include<conio.h>
#include<ctype.h>
#include<math.h>
#include<string.h>
void main()
{
int a,b,i,j,t,x,n,k=0,flag=0,prime[100];
char m[20],pp[20];
float p[20],c[20];
double e,d;
clrscr();
for(i=0;i<50;i++)
{
flag=0;
for(j=2;j<i/2;j++)
if(i%j==0)
{
flag=1;
break;
}
if(flag==0)
prime[k++]=i;
}
a=prime[k-1];
b=prime[k-2];
n=a*b;
t=(a-1)*(b-1);
KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 60
COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING
e=(double)prime[2];
d=1/(float)e;
printf("\nKey of encryption is:%lf\n",d);
printf("\nEnter plain the text:");
scanf("%s",&m);
x=strlen(m);
printf("\nDecryption status From Source to Destination:\n");
printf("\nSource\t->----------------------------------<-destination\n");
printf("\nChar\tnumeric\tcipher\t\tnumeric\t\tchar \n");
printf("\n***********************************************************\n");
printf("\n");
for(i=0;i<x;i++)
{
printf("%c",m[i]);
printf("\t%d",m[i]-97);
c[i]=pow(m[i]-97,(float)e);
c[i]=fmod(c[i],(float)n);
printf("\t%f",c[i]);
p[i]=pow(c[i],(float)d);
p[i]=fmod(p[i],(float)n);
printf("\t%f",p[i]);pp[i]=p[i]+97;
printf("\t%c\n",pp[i]);
printf("\n***********************************************************\n");
printf("\n");
}
getch();
}
Output: