0% found this document useful (1 vote)
428 views

Computer Networks Lab Manual R18

This document appears to be a lab manual for a Computer Networks course. It includes instructions for students on lab procedures and expectations. It also lists 8 experiments related to networking topics like data link layer framing methods, CRC polynomials, routing algorithms, encryption/decryption, and configuring a routing table. The document was created by the Khamma Institute of Technology & Sciences for their III-B.Tech I-SEM students.

Uploaded by

Naga Kalyan
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
428 views

Computer Networks Lab Manual R18

This document appears to be a lab manual for a Computer Networks course. It includes instructions for students on lab procedures and expectations. It also lists 8 experiments related to networking topics like data link layer framing methods, CRC polynomials, routing algorithms, encryption/decryption, and configuring a routing table. The document was created by the Khamma Institute of Technology & Sciences for their III-B.Tech I-SEM students.

Uploaded by

Naga Kalyan
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 63

COMPUTER NETWORKS

LAB MANUAL

III-B.TECH I-SEM

JNTUH-R18

Faculty In-charge:
COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 1


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 2


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 3


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 4


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 5


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 6


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 7


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 8


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 9


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 10


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 11


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 12


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 13


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 14


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 15


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 16


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 17


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 18


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 19


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 20


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 21


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 22


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 23


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 24


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 25


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 26


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

………………………………………………………
000000000000000000000000000000000000000
000000000000000000000000000000000000000
00000000000000000000000000000.A.SATISH,
Asst.Prof.

DEPARTMENT OF
COMPUTER SCIENCE ANDENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 27


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

COMPUTER NETWORKS LAB

COMPUTER NETWORKS LAB

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 .

3. Implement Dijkstra‘s algorithm to compute the Shortest path thru a graph.

4. Take an example subnet graph with weights indicating delay between nodes.
Now obtain Routing table art each node using distance vector routing algorithm

5. Take an example subnet of hosts. Obtain broadcast tree for it.

6. Take a 64 bit playing text and encrypt the same using DES algorithm.

7. Write a program to break the above DES coding

8. Using RSA algorithm encrypts a text data and Decrypt the same.

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 28


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 29


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 30


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

COMPUTER NETWORKS LAB

Course Objectives:

 To Understand the functionalities of various layers of OSI model

 To understand the operating System functionalities

Course Outcomes:

 Ability to understand the encryption and decryption concepts in Linux


environment

 Ability to apply appropriate algorithm for the finding of shortest route

.
 Ability to configure the routing table

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 31


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

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.

4. Students are instructed not to bring mobile phones to 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.

Never copy the output from other students.

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 32


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

1. Implement the data link layer framing methods such as character,


character stuffing,and bit stuffing

a) Aim:Implement the data link layer framing methods such as Bit


Stuffing.

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;

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 33


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

for(j=n;j>=pos;j--)
{
k=j+1;
a[k]=a[j];
}
a[pos]=0;
n=n+1;
}
}

else
c=0;
}

printf("\n DATA AFTER STUFFING \n");


printf(" 01111110 ");

for(i=0;i<n;i++)
{
printf("%d",a[i]);
}
printf(" 01111110 ");
getch();
}

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 34


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

Output:

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 35


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

1) b) Aim: Implement the data link layer framing methods such as


Character Stuffing and also De-stuff it
Program:

#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)

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 36


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

{
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++;

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 37


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

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:");

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 38


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

for(i=0;i<j;i++)
{printf("%c",t[i]);
}
}

Output:

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 39


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

2. Implement on a data set of characters the three CRC polynomials –


CRC 12, CRC 16 and CRC CCIP
Aim: Implement on a data set of characters the CRC polynomials.
Program:

#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')

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 40


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

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();
}

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 41


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

Output:
enter data:1101011011
enter key:10011
quotient is 1100001010
remainder is 1110
final data is:1101011011 1110

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 42


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

3.Aim:Implement Dijkstra's algorithm to compute the Shortest path


through a graph.
Program:

#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]);

printf("\nEnter the starting node:");


scanf("%d",&u);
dijkstra(G,n,u);

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;

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 43


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

//pred[] stores the predecessor of each node


//count gives the number of nodes seen so far
//create the cost matrix
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(G[i][j]==0)
cost[i][j]=INFINITY;
else
cost[i][j]=G[i][j];

//initialize pred[],distance[] and visited[]


for(i=0;i<n;i++)
{
distance[i]=cost[startnode][i];
pred[i]=startnode;
visited[i]=0;
}
distance[startnode]=0;
visited[startnode]=1;
count=1;

while(count<n-1)
{
mindistance=INFINITY;

//nextnode gives the node at minimum distance


for(i=0;i<n;i++)
if(distance[i]<mindistance&&!visited[i])
{
mindistance=distance[i];

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 44


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

nextnode=i;
}

//check if a better path exists through nextnode


visited[nextnode]=1;
for(i=0;i<n;i++)
if(!visited[i])
if(mindistance+cost[nextnode][i]<distance[i])
{
distance[i]=mindistance+cost[nextnode][i];
pred[i]=nextnode;
}
count++;
}

//print the path and distance of each node


for(i=0;i<n;i++)
if(i!=startnode)
{
printf("\nDistance of node%d=%d",i,distance[i]);
printf("\nPath=%d",i);

j=i;
do
{
j=pred[j];
printf("<-%d",j);
}while(j!=startnode);
}
}

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 45


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

Output:

enter no.of vertices:5

Enter the adjacency matrix


0 10 0 30 100
10 0 50 0 0
0 50 0 20 10
30 0 20 0 60
100 0 10 60 0

Enter the starting node:0


Distance of node 1:10
Path:1<-0
Distance of node 2:50
Path:2<-3<-0
Distance of node 3:30
Path:3<-0
Distance of node 4:60
Path:4<-2<-3<-0

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 46


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

4. Take an example subnet graph with weights indicating delay between


nodes. Now obtain Routing table art each node using distance vector
routing algorithm

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
{

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 47


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

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();
}

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 48


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

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

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 49


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

5. Take an example subnet of hosts. Obtain broadcast tree for it.


Aim:Take an example subnet of hosts. Obtain broadcast tree for it.
Program: a)Network Address:
#include<stdio.h>
#include<conio.h>
void main()
{
unsigned int compad[4];
unsigned int mask[4];
unsigned int netadr[4];
int i;
clrscr();
printf("Enter the ip address:\n");
scanf("%u%*c%u%*c%u%*c%u
%*c",&compad[3],&compad[2],&compad[1],&compad[0]);
printf("Enter the subnet address:\n");
scanf("%u%*c%u%*c%u%*c%u%*c",&mask[3],&mask[2],&mask[1],&mask[0]);
for(i=0;i<4;i++)
{
netadr[i]= compad[i]&mask[i];
}
printf("\nNetwork address is:\n");
printf("%u.%u.%u.%u",netadr[3],netadr[2],netadr[1],netadr[0]);
printf("\nsubnet address is:\n");
printf("%u.%u.%u.%u",mask[3],mask[2],mask[1],mask[0]);
printf("\nip address is:\n");
printf("%u.%u.%u.%u",compad[3],compad[2],compad[1],compad[0]);
getch();}

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 50


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

Output:

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 51


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

b)Network address with automatic subnet address generation:


#include<stdio.h>
void main()
{
unsigned int compad[4];
unsigned int mask[4];
unsigned int netadr[4];
unsigned long int ma=0;
int i,pre;
clrscr();
printf("Enter the ip address:\n");
scanf("%u%*c%u%*c%u%*c%u
%*c",&compad[3],&compad[2],&compad[1],&compad[0]);
printf("Enter the prefix:\n");
scanf("%ul",&pre);
for(i=(32-pre);i<32;i++)
ma=ma|(1<<i);
for(i=0;i<4;i++)
{
mask[i]=ma%256;
ma=ma/256;
}
for(i=0;i<4;i++)
{
netadr[i]= compad[i]&mask[i];
}
printf("\nNetwork address is:\n");
printf("%u.%u.%u.%u",netadr[3],netadr[2],netadr[1],netadr[0]);
printf("\nsubnet address is:\n");
printf("%u.%u.%u.%u",mask[3],mask[2],mask[1],mask[0]);

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 52


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

printf("\nip address is:\n");


printf("%u.%u.%u.%u",compad[3],compad[2],compad[1],compad[0]);
getch();
}

Output:

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 53


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

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 ()

Int i, ch, lp;

char cipher [50], plain[50];char key[50];

clrscr ();

while(1)

printf("\n-----MENU-----\n");

printf("\n1:Data Encryption\t\n\n2: Data Decryption\t\n\n3: Exit");

printf("\n\nEnter your choice :");

scanf ("%d",&ch);

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 54


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

switch (ch)

Case 1:

printf("\data Encryption");

Printf ("\nEnter the plain text :");

fflush (stdin);

gets (plain);

Printf ("\nEnter the encryption key :");

gets (key);

lp=strlen(key);

for (i=0;plain[i]!='\0';i++)

cipher[i]=plain[i]^lp;cipher[i]='\0';

printf("\nThe encrypted text is :");

Puts (cipher);

break;

case 2:

printf("\nData decryption");

for(i=0;cipher[i]!='\0';i++)

plain[i]=cipher[i]^lp;

printf ("\decrypted text is :");


KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 55
COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

puts (plain);

break;

case 3:

Exit (0);

getch ();

OUT PUT:

--------- MENU--------

1: Data Encryption

2: Data Decryption

3: Exit

Enter Your Choice: 1

Data Encryption

Enter the plain text: murali

Enter the Encryption key : abc

The encrypted text is :nvqboj

--------- MENU--------

1: Data Encryption

2: Data Decryption
KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 56
COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

3: Exit

Enter Your Choice: 2

Data Decryption

The decrypted text is : murali

--------- MENU--------

1: Data Encryption

2: Data Decryption

3: Exit

Enter Your Choice: 3

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 57


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

7. Write a program to break the above DES coding

AIM: Write a program to break the above DES coding

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;

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 58


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

if(num[i]<0)num[i]=26+num[i];
pwd[i]=alpha[num[i]];
}
printf("\nDecrypted text is:%s",pwd);
getch();
}

Output:

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 59


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

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();
}

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 61


COMPUTER NETWORKS LAB MANUAL COMPUTER SCIENCE & ENGINEERING

Output:

KHAMMAM INSTITUTE OF TECHNOLOGY & SCIENCES, KHAMMAM 62

You might also like