Nothing Special   »   [go: up one dir, main page]

Lab Manual of CN

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 45

INDEX

S.No Contents

1. Vision & Mission of the Institute & Department /PO-PSO


2. Prescribed University Syllabus
3. List of Experiments/ LAB Plan
4. Course Outcome
5. CO-PO-PSO Mapping
6. Lab Manuals
7. FAQ
Department of Computer Science and Engineering

To be leading institution in technical education providing education


Institute Vision and training enabling human resource to serve nation and world at
par with global standards in education

1)Developing state of art infrastructure which also includes


establishment of centre of excellence in pursuit of academic and
technical excellence
Institute
2)Valuing work force inculcating belongingness and professional
Mission
integrity
3)To develop human resource to solve local, regional and global
problems to make technology relevant to those who mean it most
To provide excellence by imparting knowledge to the learners
Department
Vision enabling them to become skilled professionals to be recognized
as a responsible citizen.

1) Provide quality education in the field of computer science and


engineering through experienced and qualified faculty members.
2) Motivate learners for higher studies and research oriented
Department activities by utilizing resources of Centers of Excellence.
Mission
3) Inculcate societal values, professional ethics, team work, and
leadership qualities by having exposure at National and
International level activities.
Program Educational Objectives (PEOs)
Graduates of the program are expected to be employed in IT industry or
PEO1
indulge in higher studies and research.
Graduates of the program are expected to exhibit curiosity to learn new technologies and
PEO2
work with ethical values and team work.
Graduates of the program are expected to design and develop innovative solutions related
PEO3
to real world problems of the society.

Program Outcomes (PSOs)


Solve complex problems using data structures and other advanced suitable algorithms.
PSO 1
Interpret fundamental concepts of computer systems and understand its hardware and software
PSO 2
aspect.
Analyze the constraints of the existing data base management systems and get experience on
PSO 3
large-scale analytical methods in the evolving technologies.
Develop intelligent systems and implement solutions to cater the business specific
PSO 4
requirements.

Program Specific Outcomes (POs)


PO1 Engineering knowledge

PO2 Problem analysis

PO3 Design/development of solutions


PO4 Conduct investigations of complex problems
PO5 Modern tool usage
PO6 The engineer and society
PO7 Environment and sustainability
PO8 Ethics
PO9 Individual and team work
PO10 Communication
PO11 Project management and finance
PO12 Life-long learning

KCS-653: Computer Network Lab (University Defined)


It is expected that student should capable of implementing different Algorithms and Techniques by using
Basics of C languages along with some practical Knowledge of wires and cables etc.
1. To learn handling and configuration of networking hardware like RJ-45 connector, CAT-6 cable,
crimping tool, etc.
2. Configuration of router, hub, switch etc. (using real devices or simulators)
3. Running and using services/commands like ping, trace route, nslookup, arp, telnet, ftp, etc.
4. Network packet analysis using tools like Wireshark, tcpdump, etc.
5. Network simulation using tools like Cisco Packet Tracer, NetSim, OMNeT++, NS2, NS3, etc.
6. Socket programming using UDP and TCP (e.g., simple DNS, data & time client/server, echo
client/server, iterative & concurrent servers)
7. Programming using raw sockets
8. Programming using RPC

Lab Plan
Teacher: Name: LP-KCS653-JT.doc
Subject Code: RCS651 SubjectName: Computer Network Lab
Session: 2020-21 Group: 3CSA/3CSB/IT

Course Objectives:
1. To expose student to implement various computer networks program using C language
2. To develop ability of using computer network to solve simple engineering problems.

Learning Outcome:
After completion of this course the students will be able to:
1. Implement various Algorithms using in C programming language.
2. Understanding of uses of various networking issues for networking field.

A. LIST OF EXPERIMENTS:

Lab Name of Experiments


No.
1 To Create Cross-Over and straight through cable.

2 Study & Implementaion of Network IP and Sub netting.

3 Connection of Computer in LAN & Configuration of router, hub, switch etc using simulators.

4 Running and using services/commands like ping, trace route, telnet,ftp etc.

5 Configure a network topology using packet tracer software

6 Configure a Network using Distance Vector and Link State Routing protocol

7 To write a program to Calculate Checksum.


8 To write a Program to compute Hamming Distance between Two Data word.

9 To write a program for error detecting code using CRC-CCITT(16-bits).

10 To write a program to Implement Hamming Code

11 To write a program for simple RSA algorithm to encrypt and decrypt the data.

12 To write a Program to Compute Link Utilization on Stop and Wait Protocol

13 To write a program for bit stuffing used in HDLC

14 To write a program for Routing algorithm to find Shortest Path.

15 To write a program to find Class of IP address and Network Address for Given IP address.

Department of Computer Science & Engineering


Course Outcomes

Subject Code:
Teacher: KCS -651
Subject Name: Computer Networks lab NBA Code:
Group: III YEAR
Session: 2020-21 CSE

C317 Course Outcomes (Statements)


C317.2 Demonstrate straight-through and cross over cables.
Implement the algorithm to solve error detecting problems in computer networks.
C317.3
Implement different encryption and decryption techniques to solve problems related to
C317.4
confidentiality and authentication.
C317.5 Implement various techniques to solve issues in data link layer.
C317.5 Implement various techniques to solve issues in network layer.

Correlation of Course Outcomes with PO & PSO


Computer NetworksLab : C317 Year of Study: 2019-20
P P
PO P P P P P P PO PO PO PSO PS PSO PS
C317 O O
1 O2 O3 O4 O5 O7 O9 10 11 12 1 O2 3 O4
6 8
C317.1 2 2 2 2
C317.
2 2 2
C317.
3 2 2
C317.
4 2
C317.
5 2 1
2 2 2 1.66 2
C317 7

[Course
Coordinator] [Module Coordinator]

EXPERIMENTAL SETUP DETAILS


Software Requirements

Command Prompt and Cisco Packet Tracer Software.

Hardware Requirements

RJ45 connector
Clamping tool
COURSE :B.Tech(CSE) Subject: Lab - CN (RCS-651)

Experiment No. 1

To Create Cross-Over and straight through cable.


Common Ethernet network cable are straight and crossover cable. This Ethernet network cable is made of 4
pair high performance cable that consists twisted pair conductors that used for data transmission. Both end of
cable is called RJ45 connector.

The cable can be categorized as Cat 5, Cat 5e, Cat 6 UTP cable. Cat 5 UTP cable can support 10/100 Mbps
Ethernet network, whereas Cat 5e and Cat 6 UTP cable can support Ethernet network running at 10/100/1000
Mbps. You might heard about Cat 3 UTP cable, it's not popular anymore since it can only support 10 Mbps
Ethernet network.

Straight and crossover cable can be Cat3, Cat 5, Cat 5e or Cat 6 UTP cable, the only difference is each type
will have different wire arrangement in the cable for serving different purposes.

Straight Cable

You usually use straight cable to connect different type of devices. This type of cable will be used most of the
time and can be used to:

1) Connect a computer to a switch/hub's normal port.


2) Connect a computer to a cable/DSL modem's LAN port.
3) Connect a router's WAN port to a cable/DSL modem's LAN port.
4) Connect a router's LAN port to a switch/hub's uplink port. (Normally used for expanding network)
5) Connect 2 switches/hubs with one of the switch/hub using an uplink port and the other one using normal
port.

If you need to check how straight cable looks like, it's easy. Both sides (side A and side B) of cable have
wire arrangement with same color. Check out different types of straight cable that are available in the
market here.
Crossover Cable

Sometimes you will use crossover cable, it's usually used to connect same type of devices. A crossover cable
can be used to:

1) Connect 2 computers directly.


2) Connect a router's LAN port to a switch/hub's normal port. (normally used for expanding network)
3) Connect 2 switches/hubs by using normal port in both switches/hubs.

In you need to check how crossover cable looks like, both side (side A and side B) of cable have wire
arrangement with following different color . Have a look on these crossover cables if you plan to buy one.
You can also find more network cable choices and information from Comtrad Cables.
In case you need to make a crossover cable yourself! You can use this crimper to do it.

Lastly, if you still not sure which type of cable to be used sometimes, try both cables and see which works.

Note: If there is auto MDI/MDI-X feature support on the switch, hub, network card or other network devices,
you don't have to use crossover cable in the situation which I mentioned above. This is because crossover
function would be enabled automatically when it's needed.

How do you make a straight-through cable?

1. Step 1: Strip the cable jacket about 1.5 inch down from the end.
2. Step 2: Spread the four pairs of twisted wire apart. ...
3. Step 3: Untwist the wire pairs and neatly align them in the T568B orientation. ...
4. Step 4: Cut the wires as straight as possible, about 0.5 inch above the end of the jacket.

How do you make a cross-over cable?

1. Using a cable stripping tool, strip about 1/3"of the out jacket of the cat-5 cable. ...
2. Assemble the pairs of wires in the following order for network cables (EAI standard / TIA-568B).
3. Insert the wires into the RJ45 jack
COURSE: B.Tech (CSE) Subject: Lab - CN (KCS-653)

Experiment No. 2
NETWORK IP AND SUB NETTING.

Aim: Study of network IP


Classification of IP address
Sub netting

Apparatus (Software): NA

Procedure: Following is required to be study under this practical.


Classification of IP address
As show in figure we teach how the ip addresses are classified and when they are used.

Class Address Range Supports Class A


1.0.0.1 to 126.255.255.254 Supports 16 million hosts on each of 127 networks.
Class B
Class C 128.1.0.1 to 191.255.255.254 Supports 65,000 hosts on each of 16,000 networks.
Class D
Class E 192.0.1.1 to 223.255.254.254 Supports 254 hosts on each of 2 million networks.

to 239.255.255.255 Reserved for multicast groups.

240.0.0.0 to 254.255.255.254 Reserved.


SUB NETTING

Subnetting is a process of dividing large network into the smaller networks based on layer 3 IP address. Every
computer on network has an IP address that represent its location on network. Two version of IP addresses are
available IPv4 and IPv6. In this article we will perform subnetting on IPv4.
IPv4
IP addresses are displayed in dotted decimal notation, and appear as four numbers separated by dots. Each
number of an IP address is made from eight individual bits known as octet. Each octet can create number value
from 0 to 255. An IP address would be 32 bits long in binary divided into the two components, network
component and host component. Network component is used to identify the network that the packet is intend
for, and host component is used to identify the individual host on network.
IP addresses are broken into the two components:

Network component: - Defines network segment of device.


Host component: - Defines the specific device on a particular network segment
IP Classes in decimal notation
Class A addresses range from 1-126
Class B addresses range from 128-191
Class C addresses range from 192-223
Class D addresses range from 224-
239 Class E addresses range from
240-254
 0 [Zero] is reserved and represents all IP addresses.
 127 is a reserved address and is used for testing, like a loop back on an interface.
 255 is a reserved address and is used for broadcasting purposes.
This tutorial is the second part of our article “Network Addressing Explained with Subnetting
and VLSM”. You can read other parts of this article here.

Basic of Network Addressing

This tutorial is the first part of this article. In this introductory part I explained how computers
find each other in network with basic terminology of network addressing.

VLSM Tutorial with Examples

This tutorial is the last part of this article. In this part I will explain VLSM in detail with
examples. Later I will provide a unique six steps method of VLSM that will help you in
learning VLSM rapidly.
Subnet mask
Subnet mask is a 32 bits long address used to distinguish between network address and host
address in IP address. Subnet mask is always used with IP address. Subnet mask has only one
purpose, to identify which part of an IP address is network address and which part is host
address.
For example how will we figure out network partition and host partition from IP address
192.168.1.10 ? Here we need subnet mask to get details about network address and host
address.
 In decimal notation subnet mask value 1 to 255 represent network address and value 0 [Zero]
represent host address.
 In binary notation subnet mask ON bit [ 1] represent network address
while OFF bit[0] represent host address.
In decimal notation
IP address 192.168.1.10
Subnet mask 255.255.255.0

Network address is 192.168.1 and host address is 10.


In binary notation
IP address 11000000.10101000.00000001.00001010

Subnet mask 11111111.11111111.11111111.00000000

Network address is 11000000.10101000.00000001 and host address is 00001010

IP Class Default Subnet Network bits Host bits Total hosts Valid hosts

A 255.0.0.0 First 8 bits Last 24 bits 16, 777, 216 16, 777, 214

B 255.255.0.0 First 16 bits Last 16 bits 65,536 65,534

C 255.255.255.0 First 24 bits Last 8 bits 256 254

Network ID
First address of subnet is called network ID. This address is used to identify one segment or
broadcast domain from all the other segments in the network.
Block Size
Block size is the size of subnet including network address, hosts addresses and broadcast
address.
Broadcast ID
There are two types of broadcast, direct broadcast and full broadcast.
Direct broadcast or local broadcast is the last address of subnet and can be hear by all hosts in
subnet.
Full broadcast is the last address of IP classes and can be hear by all IP hosts in network. Full
broadcast address is 255.255.255.255
The main difference between direct broadcast and full broadcast is that routers will not
propagate local broadcasts between segments, but they will propagate directed broadcasts.
Host Addresses
All address between the network address and the directed broadcast address is called host
address for the subnet. You can assign host addresses to any IP devices such as PCs, servers,
routers, and switches.
COURSE: B.Tech (CSE) Subject: Lab - CN (KCS-653)

Experiment No. 3
CONNECTION OF COMPUTER IN LAN

Procedure: On the host computer

On the host computer, follow these steps to share the Internet connection:

1. Log on to the host computer as Administrator or as Owner.


2. Click Start, and then click Control Panel.
3. Click Network and Internet Connections.
4. Click Network Connections.
5. Right-click the connection that you use to connect to the Internet. For example, if you
connect to the Internet by using a modem, right-click the connection that you want under Dial-
up / other network available.
6. Click Properties.
7. Click the Advanced tab.
8. Under Internet Connection Sharing, select the Allow other network users to connect through
this computer's Internet connection check box.
9. If you are sharing a dial-up Internet connection, select the Establish a dial-up connection
whenever a computer on my network attempts to access the Internet check box if you want to
permit your computer to automatically connect to the Internet.
10. Click OK. You receive the following message:
When Internet Connection Sharing is enabled, your LAN adapter will be set to use IP address
192.168.0.1. Your computer may lose connectivity with other computers on your network. If
these other computers have static IP addresses, it is a good idea to set them to obtain their IP
addresses automatically. Are you sure you want to enable Internet Connection Sharing?
11. Click Yes.
The connection to the Internet is shared to other computers on the local area network (LAN).
The network adapter that is connected to the LAN is configured with a static IP address of
192.168.0.1 and a subnet mask of 255.255.255.0

On the client computer

To connect to the Internet by using the shared connection, you must confirm the LAN adapter
IP configuration, and then configure the client computer. To confirm the LAN adapter IP
configuration, follow these steps:
1. Log on to the client computer as Administrator or as Owner.
2. Click Start, and then click Control Panel.
3. Click Network and Internet Connections.
4. Click Network Connections.
5. Right-click Local Area Connection and then click Properties.
6. Click the General tab, click Internet Protocol (TCP/IP) in the connection uses the following
items list, and then click Properties.
7. In the Internet Protocol (TCP/IP) Properties dialog box, click Obtain an IP address
automatically (if it is not already selected), and then click OK.
Note: You can also assign a unique static IP address in the range of 192.168.0.2 to
192.168.0.254. For example, you can assign the following static IP address, subnet mask, and
default gateway:
8. IP Address 192.168.31.202
9. Subnet mask 255.255.255.0
10. Default gateway 192.168.31.1
11. In the Local Area Connection Properties dialog box, click OK.
12. Quit Control Panel.
COURSE: B.Tech (CSE) Subject: Lab - CN (KCS-653)

Experiment No. 4

Running and using services/commands like ping, trace route, telnet, ftp etc.
PING:

ping(8)sends an ICMP ECHO_REQUEST packet to the specified host. If the host


responds, you get an ICMP packet back. Sound strange? Well, you can “ping” an IP
address to see if a machine is alive. If there is no response, you know something is
wrong. Here is an example conversation between two Linux users:

User Loki's down again.


User B: Are you sure?
User A: Yeah, I tried pinging it, but there's no response.

It's instances like these that make ping a very useful day-to-day command. It provides
a very quick way to see if a machine is up and connected to the network. The basic
syntax is:

% ping www.slackware.com

TRACEROUTE:

Slackware's traceroute command is a very useful network diagnostic tool. traceroute


displays each host that a packet travels through as it tries to reach its destination. You can see
how many “hops” from the Slackware web site you are with this command:

% traceroute www.slackware.com

NSLOOKUP:
nslookup is a tried and true program that has weathered the ages. nslookup has been
deprecated and may be removed from future releases. There is not even a man page for this
program.
% nslookup 64.57.102.34
Note: nslookup is deprecated and may be removed from future releases.
Consider using the `dig' or `host' programs instead. Run nslookup with
the `-sil[ent]' option to prevent this message from appearing.
Server: 192.168.1.254
Address: 192.168 1.254#53

Non-authoritative answer:
www.slackware.com canonical name =
slackware.com. Name: slackware.com
Address: 64.57.102.34

TELNET:
Telnet allows you to log in to a computer, just as if you were sitting at the terminal. Once
your username and password are verified, you are given a shell prompt. From here, you can
do anything requiring a text console. Compose email, read newsgroups, move files around,
and so on. If you are running X and you telnet to another machine, you can run X programs
on the remote computer and display them on yours.

To login to a remote machine, use this syntax:

% telnet <hostname>
COURSE: B.Tech (CSE) Subject: Lab - CN (KCS-653)

Experiment No. 4

CONFIGURE A NETWORK TOPOLOGY USING PACKET TRACER


SOFTWARE

Apparatus (Software): Packet tracer Software

Procedure: To implement this practical following network topology is required to be


configured using the commands learned in previous practical. After configuring the given
network a packet should be ping from any one machine to another.
COURSE: B.Tech (CSE) Subject: Lab - CN (KCS-653)

Experiment No. 6

CONFIGURE A NETWORK USING DISTANCE VECTOR ROUTING


PROTOCOL
Aim: Configure a Network using Distance Vector Routing protocol.
• RIP

Apparatus (Software): packet tracer software

Procedure:

1. Develop a Topology shown in figure given below.


2. Configure all Routers
3. Implement RIP protocols in Router to configure Network.
CONFIGURE A NETWORK USING LINK STATE VECTOR ROUTING
PROTOCOL

Aim: Configure Network using Link State Vector Routing protocol.

• OSPF

Apparatus (Software): Packet Tracer Software

Procedure:

1. Develop a Topology shown in figure given below.


2. Configure all the workstations
3. Configure all switches
4. Configure all Routers
5. Implement OSPF protocols in Router to configure Network
COURSE: B.Tech (CSE) Subject: Lab - CN (KCS-653)

Experiment No. 7
To write a program to Calculate Checksum
Theory:
A checksum is a error detection method in Data Communication. It is used for errors which
may have been introduced during transmission or storage. It is usually applied to an
installation file after it is received from the download server.
Checksum method can only detect errors but is unable to correct the error.

In this method a checksum is calculated based on the given binary strings which is sent with
the data as redundant bits. This data + checksum is received at receiver end and checksum is
calculated again, if checksum is 0 it means no error in data received, else there exists some
error in the received data.

Program:
#include<stdio.h>

1. #include<conio.h>
2. #include<math.h>

3.

4. intsender(int b[10],int k)

5. {

6. intchecksum,sum=0,i;

7. printf("\n****SENDER****\n");

8.

9. for(i=0;i<k;i++)

10. sum+=b[i];

11. printf("SUM IS: %d",sum);

12.

13. checksum=~sum;

14. printf("\nSENDER's CHECKSUM IS:%d",checksum);

15. return checksum;

16. }

22
17.

18. intreceiver(int c[10],intk,intscheck)

19. {

20. intchecksum,sum=0,i;

21. printf("\n\n****RECEIVER****\n");

22. for(i=0;i<k;i++)

23. sum+=c[i];

24. printf(" RECEIVER SUM IS:%d",sum);

25. sum=sum+scheck;

26. checksum=~sum;

27. printf("\nRECEIVER's CHECKSUM IS:%d",checksum);

28. return checksum;

29. }

30. main()

31. {

32. inta[10],i,m,scheck,rcheck;

33. clrscr();

34. printf("\nENTER SIZE OF THE STRING:");

35. scanf("%d",&m);

36. printf("\nENTER THE ELEMENTS OF THE ARRAY:");

37. for(i=0;i<m;i++)

38. scanf("%d",&a[i]);

39. scheck=sender(a,m);

40. rcheck=receiver(a,m,scheck);

41. if(rcheck==0)

23
42. printf("\n\nNO ERROR IN TRANSMISSION\n\n");

43. else

44. printf("\n\nERROR DETECTED");

45. getch();

46. }

Output:

Experiment No. 8

Write a Program to compute Hamming Distance between Two Data word


Theory:
You are given two strings of equal length, you have to find the Hamming Distancebetween
24
these string.
Where the Hamming distance between two strings of equal length is the number of positions
at which the corresponding character are different.

Program:

void
main()
{ int
a[10];
int
b[10];
int c=0;
int i,n;
clrscr();
printf("enter the length of data code\n");
scanf("%d",&n);
printf("enter the sender side data code\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("enter the reciver side datacode\n");
for(i=0;i<n;i++)
{
scanf("%d",&b[i]);
}
for(i=0;i<n;i++)
{ if(a[i]!
=b[i])
{ c+
+; } }
printf("hamming distance is %d",c);
getch();

OUTPUT:
enter the length of data code 6

enter the sender side data code

0
0

25
1 1 enter the receiver side

data code

Hamming distance is 2

Experiment No. 9

Write a program for error detecting code using CRC-CCITT (16-bits).

Theory-
26
It does error checking via polynomial division. In general, a bit
string bn-1bn-2bn-3…b2b1b0 As bn-1Xn-1+ bn-2 Xn-2+ bn-3
Xn-3+ …b2 X2+ b1 X1+ b0

For example- 10010101110 can be expressed as X10 + X7 + X5 + X3 + X2 + X1

All computations are done in modulo 2.

Algorithm:-
1- Given a bit string, append 0S to the end of it (the number of 0s is the same as
the degree of the generator polynomial) let B(x) be the polynomial corresponding to B.
2- Divide B(x) by some agreed on polynomial G(x) (generator polynomial) and
determine the remainder R(x). This division is to be done using Modulo 2
Division.
3- Define T(x) = B(x) –R(x)
(T(x)/G(x) => remainder 0)
4- Transmit T, the bit string corresponding to T(x).
5- Let T’ represent the bit stream the receiver gets and T’(x) the associated
polynomial. The receiver divides T1(x) by G(x). If there is a 0 remainder, the
receiver concludes T = T’ and no error occurred otherwise, the receiver concludes
an error occurred and requires a retransmission.

Program :

#include<stdio.h>
#include<string.h>
#include<conio.h>
#define N strlen(g)
char t[128], cs[128],
g[]="10001000000100001"; int a, e, c; void
xor()
{
for(c=1;c<N;c++) cs[c]=((cs[c]==g[c])?'0':'1');
} void
crc()
{
for(e=0;e<N;e++)
cs[e]=t[e]; do {
if(cs[0]=='1') xor();
for(c=0;c<N-1;c++) cs[c]=cs[c+1];
cs[c]=t[e++];
}while(e<=a+N-1);
}
void main() { clrscr(); printf("\nEnter
poly : "); scanf("%s",t); printf("\
nGenerating Polynomial is : %s",g);
a=strlen(t); for(e=a;e<a+N-
1;e++)
t[e]='0';
printf("\nModified t[u] is : %s",t);
27
crc();
printf("\nChecksum is : %s",cs);
for(e=a;e<a+N-1;e++) t[e]=cs[e-a]; printf("\
nFinal Codeword is : %s",t); printf("\nTest
Error detection 0(yes) 1(no) ? : ");
scanf("%d",
&e);
if(e==0) {
printf("Enter position where error is to inserted : ");
scanf("%d",&e);
t[e]=(t[e]=='0')?'1':'0';
printf("Errorneous data : %s\n",t);
}
crc();
for (e=0;(e<N-1)&&(cs[e]!
='1');e++); if(e<N-1)
printf("Error detected."); else
printf("No Error Detected.");
getch(); }

OUTPUT :
Enter poly : 1011101
Generating Polynomial is : 10001000000100001
Modified t[u] is : 10111010000000000000000
Checksum is : 1000101101011000
Final Codeword is : 10111011000101101011000
Test Error detection 0(yes) 1(no) ? : 0
Enter position where you want to insert error : 3
Errorneous data : 10101011000101101011000
Error detected.
Enter poly : 1011101
Generating Polynomial is : 10001000000100001
Modified t[u] is : 10111010000000000000000

Checksum is : 1000101101011000
Final Codeword is :
10111011000101101011000 Test Error
detection 0(yes) 1(no) ? : 1 No Error
Detected.

28
Experiment No. 10
To write a program to Implement HammingCode
Theory:
Hamming code is a popular error detection and error correction method in data communication. Hamming
code can only detect 2 bit error and correct a single bit error which means it is unable to correct burst errors if
may occur while transmission of data.
Program:
#include<stdio.h>

voidmain(){

intdata[10];

intdataatrec[10],c,c1,c2,c3,i;

printf("Enter 4 bits of data one by one\n");

scanf("%d",&data[0]);

scanf("%d",&data[1]);

scanf("%d",&data[2]);

scanf("%d",&data[4]);

//Calculation of even parity

data[6]=data[0]^data[2]^data[4];

data[5]=data[0]^data[1]^data[4];

data[3]=data[0]^data[1]^data[2];

printf("\nEncoded data is\n");

for(i=0;i<7;i++)

printf("%d",data[i]);

printf("\n\nEnter received data bits one by one\n");

for(i=0;i<7;i++)

29
scanf("%d",&dataatrec[i]);

c1=dataatrec[6]^dataatrec[4]^dataatrec[2]^dataatrec[0];

c2=dataatrec[5]^dataatrec[4]^dataatrec[1]^dataatrec[0];

c3=dataatrec[3]^dataatrec[2]^dataatrec[1]^dataatrec[0];

c=c3*4+c2*2+c1;

if(c==0){

printf("\nNo error while transmission of data\n");

else{

printf("\nError on position %d",c);

printf("\nData sent : ");

for(i=0;i<7;i++)

printf("%d",data[i]);

printf("\nData received : ");

for(i=0;i<7;i++)

printf("%d",dataatrec[i]);

printf("\nCorrect message is\n");

//if errorneous bit is 0 we complement it else vice versa

if(dataatrec[7-c]==0)

dataatrec[7-c]=1;

else

30
dataatrec[7-c]=0;

for(i=0;i<7;i++){

printf("%d",dataatrec[i]);

Output
Enter 4 bits of data one by one
1
0
1
0
Encoded data is
1010010
Enter
received data bits one by one
1
0
1
0
0
1
0
No error while transmission of data

Experiment No. 11
31
Write a program for simple RSA algorithm to encrypt and decrypt the data.

Theory-
Cryptography has a long and colorful history. The message to be encrypted, known as the plaintext, are
transformed by a function that is parameterized by a key. The output of the encryption process, known as the
ciphertext, is then transmitted, often by messenger or radio. The enemy, or intruder, hears and accurately
copies down the complete ciphertext. However, unlike the intended recipient, he does not know the decryption
key and so cannot decrypt the ciphertext easily. The art of breaking ciphers is called cryptanalysis the art of
devising ciphers
(cryptography) and breaking them
(cryptanalysis) is collectively known as cryptology.
There are several ways of classifying cryptographic algorithms. They are generally categorized based on the
number of keys that are employed for encryption and decryption, and further defined by their application and
use. The three types of algorithms are as follows:

1- Secret Key Cryptography (SKC): Uses a single key for both encryption and decryption. It is also
known as symmetric cryptography.
2- Public Key Cryptography (PKC): Uses one key for encryption and another for decryption. It is
also known as asymmetric cryptography.
3- Hash Functions: Uses a mathematical transformation to irreversibly "encrypt" Information.

Public-key cryptography has been said to be the most significant new development in cryptography. Modern
PKC was first described publicly by Stanford University professor Martin Hellman and graduate student
Whitfield Diffie in 1976. Their paper described a two-key crypto system in which two parties could engage in
a secure communication over a non-secure communications channel without having to share a secret key.

Generic PKC employs two keys that are mathematically related although knowledge of one key does not allow
someone to easily determine the other key. One key is used to encrypt the plaintext and the other key is used to
decrypt the ciphertext. The important point here is that it does not matter which key is applied first, but that
both keys are required for the process to work. Because pair of keys is required, this approach is also called
asymmetric cryptography.

In PKC, one of the keys is designated the public key and may be advertised as widely as the owner wants. The
other key is designated the private key and is never revealed to another party. It is straight forward to send
messages under this scheme.

Algorithm
1- Generate two large random primes, P and Q, of approximately equal size. 2- Compute N
=PxQ
3- Compute Z = (P-1) x (Q-1).
4- Choose an integer E, 1 <E <Z, such that GCD (E, Z) = 1
5- Compute the secret exponent D, 1 <D <Z, such that E x D ≡ 1 (mod Z)
6- The public key is (N, E) and the private key is (N, D).

Note: The values of P, Q, and Z should also be kept secret.


The message is encrypted using public key and decrypted using private key. An example
of RSA encryption 1- Select primes P=11, Q=3.
2- N = P x Q = 11 x 3 = 33
32
Z = (P-1) x (Q-1) = 10 x 2 = 20
3- Lets choose E=3
Check GCD(E, P-1) = GCD(3, 10) = 1 (i.e. 3 and 10 have no common factors except
1), and check GCD(E, Q-1) = GCD(3, 2) = 1 therefore GCD(E, Z) = GCD(3, 20) = 1 4-
Compute D such that E x D ≡ 1 (mod Z) compute D = E^-1 mod Z = 3^-1 mod 20 find a
value for D such that Z divides ((E x D)-1) find D such that 20 divides 3D-1.
Simple testing (D = 1, 2, ...) gives D = 7
Check: (E x D)-1 = 3.7 - 1 = 20, which is divisible by Z. 5- Public
key = (N, E) = (33, 3) Private key = (N, D) = (33, 7).
Now say we want to encrypt the message m = 7, Cipher code =
M^E mod N
= 7^3 mod 33 = 343 mod 33 = 13. Hence the
ciphertext c = 13.
To check decryption we compute Message’ = C^D mod N
= 13^7 mod 33 = 7.
Note : It is not needed to calculate the full value of 13 to the power 7 here. We can make use of the fact that a
= bc mod n = (b mod n).(c mod n) mod n so we can break down a potentially large number into its components
and combine the results of easier, smaller calculations to calculate the final value.

Program :
#include <stdio.h>
#include <string.h>
#include <conio.h> #include <math.h>
int mult(unsigned int x, unsigned int y, unsigned int n)
{
unsigned long int k=1;
int j;
for (j=1; j<=y; j++) k = (k * x) % n; return (unsigned
int) k;
}
void main ()
{ char msg[100];
unsigned int pt[100], ct[100], n, d, e, p, q, i; printf("Enter message : ");
gets(msg);
//strcpy(pt, msg);
for(i=0;i<strlen(msg);i++) pt[i]=msg[i]; n = 253; d = 17; e =
13; printf("\nCT = "); for(i=0; i<strlen(msg); i++) ct[i] =
mult(pt[i], e,n); for(i=0; i<strlen(msg); i++) printf("%d ", ct[i]);
printf("\nPT = ");
for(i=0; i<strlen(msg); i++) printf("%c", pt[i]); for(i=0;
i<strlen(msg); i++) pt[i] = mult(ct[i], d,n) ;
}

Output :
Enter message : alpha
CT = 113 3 129 213 113
PT = alpha

33
34
Experiment No. 12

WAP Program to Calculate the Link Utilization for Stop and Wait ARQ Protocol
Theory:
Link utilization is simply the average traffic over a particular link expressed. as a percentage of the
total link capacity. Link efficiency is a less. commonly used term that is defined as the ratio of the time taken
to. transmit a frame (or frames) of data to the total time it takes to transmit.
Program:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#define v 2.0e8
void main(void)
{
char instring[80];
double d,r,pr,p,a,u,u1;
long int l;
clrscr();
printf("....................");
printf("\n Program to Compute Utiliation of Stop and Wait Protocol\n");
printf("\n.....................\n");
printf("\n Length of the link in m:");
scanf("%s",instring);
d=atof(instring);
printf("\n Data rate of the link in bits per sec");
scanf("%s",instring);
r=atof(instring);
printf("\n Size of frame in byte:");
scanf("%s",instring);
l=8*atoi(instring);
printf("\n pr[biterror](0.0to1.0):");
scanf("%s",instring);
pr=atof(instring);
p=1-pow((1-pr),(double)l);
a=((double)r*d)/((double)v*l);
u=(1-p)/(1+(2*a));
u1=(1)/(1+(2*a));
printf("\n...................\n");
printf("\n.....Protocol is Stop and Wait....\n");
printf("......a=%f.........\n",a);
printf("......pr[frameloss]=%f....\n",p);
printf(".....Utilisation Factor with Error=%f....\n",100.0*u);
printf(".....Utilisation Factor without Error=%f....\n",100.0*u1);
printf("................\n");
getch();
}

35
OUTPUT:

36
Experiment No. 13
Write a c program for bit stuffing used in HDLC.

Theory

Bit stuffing is the insertion of one or more bits into a transmission unit as a way to provide signaling
information to a receiver. The receiver knows how to detect and remove or disregard the stuffed bits.

In another example of bit stuffing, a standard HDLC packet begins and ends with 01111110. To make sure this
sequence doesn't appear again before the end of the packet, a 0 is inserted after every five consecutive 1s.

Bit stuffing is defined by some to include bit padding, which is the addition of bits to a tranmission to make
the transmission unit conform to a standard size, but is distinct from bit robbing, a type of in-band signaling.

Program

#include<stdio.h>
#include<conio.h>
#include<string.h>
Void main()
{ intip[20];op[30];i=j=0;count=0; Printf(“enter
the i/p bit”); get(ip);
for(i=0;i<strlen(ip);i++) op[0]=ip[0];
op[j++]=ip[i];
if(ip[i]==’1’) count++;
else count=0; if(count==5)
{
Op[j++]=’0’;
Count=0;

}
}
Op[j++]=’\0’;
Printf(“bits stuffed is %s”,op); getch();
}

37
38
Experiment No. 14

To write a program for Routing algorithm to find Shortest Path.


Theory:
Dijkstra's algorithm (or Dijkstra's Shortest Path Firstalgorithm, SPF algorithm) is an algorithm for
finding the shortest paths between nodes in a graph, which may represent, for example, road networks. ... For a
given source node in the graph, the algorithm finds the shortest path between that node and every other.

Dijkstra's algorithm to find the shortest path between a and b. It picks the unvisited vertex with the lowest
distance, calculates the distance through it to each unvisited neighbor, and updates the neighbor's distance if
smaller. Mark visited (set to red) when done with neighbors.
Program:

#include<stdio.h>

#include<conio.h>

#define INFINITY 9999

#define MAX 10

void dijkstra(int G[MAX][MAX],int n,intstartnode);

int main()

int G[MAX][MAX],i,j,n,u;

printf("Enter no. of vertices:");

scanf("%d",&n);

printf("\nEnter the adjacency matrix:\n");

39
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,intstartnode)

int cost[MAX][MAX],distance[MAX],pred[MAX];

int visited[MAX],count,mindistance,nextnode,i,j;

//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

40
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];

nextnode=i;

41
//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);

42
}while(j!=startnode);

Output

43
Experiment No. 15

Write A Program to find Class of IP Address and Network Address for Given
IP Address
Theory:
TCP/IP defines five classes of IP addresses: class A, B, C, D, and E. Each class has a range of valid IP
addresses. The value of the first octet determines the class. IP addresses from the first three classes (A, B and
C) can be used for host addresses. The other two classes are used for other purposes (class D for multicast and
class E for experimental purposes).

The system of IP address classes was developed for the purpose of Internet IP addresses assignment. The
classes created were based on the network size. For example, for the small number of networks with a very
large number of hosts, the Class A was created. The Class C was created for the numerous networks with the
small number of hosts.

Classes of IP addresses are:

For the IP addresses from Class A, the first 8 bits (the first decimal number) represent the network part, while
the remaining 24 bits represent the host part. For Class B, the first 16 bits (the first two numbers) represent the
network part, while the remaining 16 bits represent the host part. For Class C, the first 24 bits represent the
network part, while the remaining 8 bits represent the host part.

Program:

void main()
{ inta,b,c,d; clrscr();
printf("enter the first octet");
scanf("%d",&a); printf("\n");
printf("enter the second octet");
scanf("%d",&b); printf("\n");
printf("enter the third octet");
scanf("%d",&c); printf("\n");
printf("enter the fourth octet");
scanf("%d",&d); printf("\n");
if((a<=127))
{
printf("enterdip address belong to class A\n");
printf("network address of given ip address is %d.0.0.0",a);
}
else if((a>127)&&(a<=191))
44
{
printf("entered ip address belong to class B\n");
printf("network address of given ip address is %d.%d.0.0",a,b);
}
else if((a>191)&&(a<=223))
{
printf("entered ipadress belong to class C\n");
printf("network address of given ip address is %d.%d.%d.0",a,b,c);
}
else if((a>223)&&(a<=241))
{
printf("entered ip address belong to class D\n");

printf("network address of given ip address is useed for reserved");


}
else if((a>241)&&(a<=255))
{
printf("entered ipadress belong to E\n");
printf("network address of given ip address is used for multicasting");

} else {
printf("please enter the valid ip address\n");
}

getch(); }

Output:

enter the first octet 123 enter the second octet 233 enter the

third octet 12 enter the fourth octet 34 entered ip address

belong to class A network address of given ip address is

123.0.0.0

45

You might also like