+ All Categories
Home > Documents > Advanced Computer Networks Practical File

Advanced Computer Networks Practical File

Date post: 18-Nov-2014
Category:
Upload: lali65
View: 2,196 times
Download: 3 times
Share this document with a friend
39
ADVANCED COMPUTER NETWORKS PRACTICAL FILE BY NEHA ROY ROLL NO-057
Transcript
Page 1: Advanced Computer Networks Practical File

ADVANCED COMPUTER NETWORKS PRACTICAL

FILE

BY NEHA ROY

ROLL NO-057

INDEX

DATE TOPIC SIGN

Page 2: Advanced Computer Networks Practical File

1. To compare IPv4 and IPv6:

Page 3: Advanced Computer Networks Practical File

PROTOCOL VERSION 4INTERNET

IPv4 uses 32-bit (four-byte) addresses, which limits the address space to 4,294,967,296 (232) possible unique addresses. However, some are reserved for special purposes such as private networks (~18 million addresses) or multicast addresses (~16 million addresses). This reduces the number of addresses that can potentially be allocated for routing on the public Internet. As addresses are being incrementally delegated to end users, an IPv4 address shortage has been developing, however network addressing architecture redesign via classful network design, Classless Inter-Domain Routing, and network address translation (NAT) has significantly delayed the inevitable exhaustion.

This limitation has stimulated the development of IPv6, which is currently in the early stages of deployment, and is the only long-term solution.

INTERNET PROTOCOL VERSION 6

Page 4: Advanced Computer Networks Practical File

Internet Protocol version 6 (IPv6) is the next-generation Internet Protocol version designated as the successor to IPv4, the first implementation used in the Internet and still in dominant use currently. It is an Internet Layer protocol for packet-switched internetworks. The main driving force for the redesign of Internet Protocol was the foreseeable IPv4 address exhaustion. IPv6 was defined in December 1998 by the Internet Engineering Task Force (IETF) with the publication of an Internet standard specification, RFC 2460.

IPv6 has a vastly larger address space than IPv4. This results from the use of a 128-bit address, whereas IPv4 uses only 32 bits. The new address space thus supports 2128 (about 3.4×1038) addresses. This expansion provides flexibility in allocating addresses and routing traffic and eliminates the primary need for network address translation (NAT), which gained widespread deployment as an effort to alleviate IPv4 address exhaustion.

IPv6 also implements new features that simplify aspects of address assignment (stateless address auto configuration) and network renumbering (prefix and router announcements) when changing Internet connectivity providers. The IPv6 subnet size has been standardized by fixing the size of the host identifier portion of an address to 64 bits to facilitate an automatic mechanism for forming the host identifier from Link Layer media addressing information (MAC address).

Network security is integrated into the design of the IPv6 architecture. Internet Protocol Security (IP sec) was originally developed for IPv6, but found widespread optional deployment first in IPv4 (into which it was back-engineered). The IPv6 specifications mandate IP sec implementation as a fundamental interoperability requirement

The fixed header makes up the first 40 octets (320 bits) of an IPv6 data packet. The format of the fixed header is presented in the table below. The octet (byte) offsets are in hexadecimal (base 16) and the bit offsets are in decimal (base 10).

Page 5: Advanced Computer Networks Practical File

Octet Offset

0 1 2 3

Bit Offset

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

0 0 Version Traffic Class Flow Label

4 32 Payload Length Next Header Hop Limit

8 64

Source Address

C 96

10 128

14 160

18 192

Destination Address

1C 224

20 256

24 288

The fields used in the header are:

Page 6: Advanced Computer Networks Practical File

Version: The number 6 encoded (bit sequence 0110). Traffic class: The packet priority (8 bits). Priority values subdivide into ranges:

traffic where the source provides congestion control and non-congestion control traffic.

Flow label: Used for QoS management (20 bits). Originally created for giving real-time applications special service, but currently unused.[14]

Payload length: The size of the payload in octets (16 bits). When cleared to zero, the option is a "Jumbo payload" (hop-by-hop).

Next header: Specifies the next encapsulated protocol. The values are compatible with those specified for the IPv4 protocol field (8 bits).

Hop limit: Replaces the time to live field of IPv4 (8 bits).

Source and destination addresses: 128 bits each.

The protocol field of IPv4 is replaced with a next header field. This field usually specifies the transport layer protocol used by a packet's payload. In the presence of options, however, the next header field specifies the presence of one or more out of six extension headers, which then follow the IPv6 header in distinct order; the payload's protocol itself is specified in the next header field of the last extension header.

Page 7: Advanced Computer Networks Practical File

2 . To determine the class of IP address from the input binary notation.

Classful Addressing

Computers communicating using Internet Protocol (IP) send datagrams. IP datagram contain a source IP address, and a destination IP address. However, an IP datagram does not contain any network subnet mask information, thus it is difficult to know which groups of computers (hosts) formed a network.Source Address

The IP address of the host that sent the datagram (sender).

Destination Address

The IP address of the host the datagram is being sent to (receiver).

CLASSES

Classful addressing divides the entire IP address space (0.0.0.0 to 255.255.255.255) into 'classes', or special ranges of contiguous IP addresses (no addresses missing between the first and last address in the range). Classful addressing makes it possible to determine the network portion of the IP address by looking at the first four bits of the first octet in the IP address. The first four bits are referred to as the 'most significant bits' of the first octet and are used to determine what class of IP address is being used. The value of the first four bits determines the range of actual numerical values of the first octet of the IP addresses in that class. From this information, a receiving host can determine which part of the IP address is being used to identify the specific network on which the host resides, and which portion of the IP address is used to identify the host.

The different classes of IP addresses (Class A, Class B, Class C, Class D & Class E) were created to allow for carving up the entire set of all IP addresses into chunks of different sizes that would 'fit' the number of hosts on the network for which the IP address space was being supplied.

Network and Host ID Fields

The four octets that make up an IP address are conventionally represented by a, b, c, and d respectively. The following table shows how the octets are distributed in classes A, B, and C.

Class IP Address Network ID Host ID

A a.b.c.d a b.c.d

B a.b.c.d a.b c.d

C a.b.c.d a.b.c D

Page 8: Advanced Computer Networks Practical File

Class A: Class A addresses are specified to networks with large number of total hosts. Class A allows for 126 networks by using the first octet for the network ID. The first bit in this octet, is always set and fixed to zero. And next seven bits in the octet is all set to one, which then complete network ID. The 24 bits in the remaining octets represent the hosts ID, allowing 126 networks and approximately 17 million hosts per network. Class A network number values begin at 1 and end at 127.

Class B: Class B addresses are specified to medium to large sized of networks. Class B allows for 16,384 networks by using the first two octets for the network ID. The two bits in the first octet are always set and fixed to 1 0. The remaining 6 bits, together with the next octet, complete network ID. The 16 bits in the third and fourth octet represent host ID, allowing for approximately 65,000 hosts per network. Class B network number values begin at 128 and end at 191.

Class C: Class C addresses are used in small local area networks (LANs). Class C allows for approximately 2 million networks by using the first three octets for the network ID. In class C address three bits are always set and fixed to 1 1 0. And in the first three octets 21 bits complete the total network ID. The 8 bits of the last octet represent the host ID allowing for 254 hosts per one network. Class C network number values begin at 192 and end at 223.

Class D and E: Classes D and E are not allocated to hosts. Class D addresses are used for multicasting, and class E addresses are not available for general use: they are reserved for future purposes

Page 9: Advanced Computer Networks Practical File

#include<stdio.h>#include<conio.h>#include<math.h>#include<iostream.h>#include<string.h>#include<process.h>

void main(){ char add[50]; clrscr(); cout<<"\n Enter IP address in binary notation:\n"; gets(add); // checks if IP address is 32 bits if(strlen(add)!=32) { cout<<"ERROR:IP address must be 32 bits long"; getch(); exit(0); }

// checks if the address is in binary int j=0; while(j!=32) { if((add[j]!='0')&&(add[j]!='1')) { cout<<"\n IP address should be in binary notation"; getch(); exit(1); } j++;}float in=0;for(int d=0;d<8;d++){ in=in + ((add[d]-48)*pow(2,(7-d)));}if((in>0)&&(in<128))cout<<"\n Address belongs to class A";else if((in>=128)&&(in<192))cout<<"\n Address belongs to class B";else if((in>=192)&&(in<224))cout<<"\n Address belongs to class C";else if((in>=224)&&(in<232))cout<<"\n Address belongs to class D";else cout<<"\n Address belongs to class E";getch();}

Page 10: Advanced Computer Networks Practical File

OUTPUT

Enter IP adress in binary notation:

00000001000010110000101111101111

Address belongs to class A

Page 11: Advanced Computer Networks Practical File

3. To determine the hardware address corresponding to the input IP address .

THEORY:

There are 3 types of addresses :

1. Physical Address :

A physical address is a local address. Its jurisdiction is a local network. It should be unique locally but not necessarily universally . It is called physical address because it is usually implemented in hardware , therefore also called hardware address . Examples of physical addresses are 48 bit MAC addresses in Ethernet protocol , which are imprinted on the NIC installed in the host or router.

2. Logical Address

The hosts and routers are recognized at the network level by their logical addresses. A logical address is an internetwork address. Its jurisdiction is universal. It is unique universally. It is called a logical address because it is usually implemented in software. Every protocol that deals with interconnecting networks requires logical addresses . The logical addresses in the TCP/IP protocol suite are called IP addresses and are 32 bits long.

3. Port Address

Today computers are devices that can run multiple processes at the same time. The end objective of Internet communication is a process communicating with another process. For processes to occur simultaneously, we need a method to label different processes. In TCP/IP architecture , the label assigned to a process is called a port address. A port address in TCP/IP is 16 bits long

Page 12: Advanced Computer Networks Practical File

Delivery of a packet to a host or a router requires two levels of addressing : logical and physical . We need to be able to map a logical address to its corresponding physical address and vice versa. These can be done using either static mapping or dynamic mapping.

Static mapping means creating a table that associates a logical address with a physical address. This table is stored in each machine on the network. Each machine that knows the IP address of another machine but not its physical address can look it up in the table. But it has some limitations

1. A machine could change its NIC, resulting in a new physical address.2. In some LAN, such as Local Talk , the physical address changes every time

the computer is turned on.3. A mobile computer can move from one physical network to another , resulting

in a change in its physical address.

In dynamic mapping each time a machine knows one of the two addresses , it can use a protocol to find the other one. Two protocols have been designed to perform dynamic mapping: address resolution protocol ( ARP – maps logical address to physical address ) and reverse address resolution protocol ( RARP – maps physical address to logical address ).

ARP

The ARP process has following steps:

1. The sender knows the IP address of the target.2. IP asks ARP to create an ARP request message, filling in the sender physical

address , sender IP address , and the target IP address. The target physical address field is filled with 0s.

3. The message is passed to the data link layer where it is encapsulated in a frame using the physical address of the sender as the source address and the physical broadcast address as the destination address.

4. Every host or router receives the frame. Because the frame contains a broadcast destination address, all stations remove the message and pass it to ARP. All machines except the one targeted drop the packet. The target machine recognizes the IP address.

5. The target machine replies with an ARP reply message. It now knows the physical address of the target machine.

6. The sender receives the reply message. It now knows the physical address of the target machine.

7. The IP datagram , which carries data for the target machine, is now encapsulated in a frame and is unicast to the destination.

Page 13: Advanced Computer Networks Practical File

RARP

The RARP process has following steps:

1. The machine gets its physical address (by reading its NIC) which is unique locally.

2. A RARP request is created and broadcast on the local network.3. This packet is received by every host (or router) on the physical network but only

RARP server will answer it. 4. The server sends a RARP reply packet that includes the IP address of the

requestor.

#include<conio.h>#include<iostream.h>#include<stdio.h>#include<string.h>#include<ctype.h>struct arp{ char ip[40]; char nic[10]; char type; arp * next;}*first,*cur;

void init();void find();int valid(char ip[35]);

void main(){ clrscr(); first=cur=NULL; init(); find(); getch();}

void init(){

int flag=1; char ip[40],nic[10],type,rep='y'; arp *temp; cout<<"\ninitialise the database...."; do{ cout<<"\nenter ip address:"; gets(ip);

Page 14: Advanced Computer Networks Practical File

flag=valid(ip); if(flag==1) cout<<"\ninvalid ip address"; else{ cout<<"\nenter physical address:"; gets(nic); temp=new arp; strcpy(temp->ip,ip); strcpy(temp->nic,nic); temp->type='r';

temp->next=NULL; if(first==NULL) { first=temp; cur=temp; } else { cur->next=temp; cur=temp; }} cout<<"\nwant to enter more?"; cin>>rep; }while(rep=='y'||rep=='Y');}void find(){ arp *temp,*ptr; char ip[40],rep='y',nic[10]; int flag,val=1; do{ flag=1; ptr=first; cout<<"\nenter ip address to find:"; gets(ip); val=valid(ip); if(val==1) cout<<"\ninvalid ip address"; else{ while(ptr!=NULL) {

Page 15: Advanced Computer Networks Practical File

if(strcmp(ptr->ip,ip)==0) { cout<<"\nphysical address of entered ip is:"<<ptr->nic; flag=0; break; } ptr=ptr->next; } if (flag!=0) { cout<<"\nrecord does not exist.enter physical address:"; gets(nic); temp=new arp; strcpy(temp->ip,ip); strcpy(temp->nic,nic); temp->type='p'; temp->next=NULL; cur->next=temp; cur=cur->next; }} cout<<"\nwant to enter more?"; cin>>rep; }while(rep=='y'||rep=='Y');}

int valid(char ip[35]){ int i; for(i=0;i<35;i++) { if(i ==8 || i == 17 || i == 26 ) {

if(ip[i]!='.') return 1;

} else {

if(ip[i]!='1' && ip[i]!='0') return 1;

} } return 0; }

Page 16: Advanced Computer Networks Practical File

OUTPUT:

initialise the database.... enter ip address:11001100.00000000.01010101.11111111 enter physical address:nic1 want to enter more?y enter ip address:10101010.01010101.10101010.01010101 enter physical address:nic2 want to enter more?n enter ip address to find:10101010.01010101.10101010.01010101

physical address of entered ip is:nic2 want to enter more?y enter ip address to find:11110000.11110000.11110000.11110000 record does not exist.enter physical address:nic3 want to enter more?n

Page 17: Advanced Computer Networks Practical File

4.To implement the routing algorithm(link state routing).

THEORY

Link State Routing Algorithm is a routing algorithm in which each router broadcasts or multicasts information regarding the cost of reaching each of its neighbors to all nodes in the internetwork. The entire routing table is not distributed from any router, only the part of the table containing its neighbors. Link state algorithms create a consistent view of the network and are therefore not prone to routing loops, but they achieve this at the cost of relatively greater computational difficulty and more widespread traffic. Some of the routing protocols using the Link State Routing Algorithm are the OSPF, IS-IS and EIGRP.

BUILDING ROUTING TABLES

In link state routing.four sets of actions are recquired to ensure that each node has the routing table showing the least cost node to every other node.

1.creation of the states of links by each node, called the link state packet.

2.Formation of a shortest path tree for each node.

3.Calculation of a routing table based on shortest path.

Page 18: Advanced Computer Networks Practical File

#include<stdio.h>

#include<conio.h> #include<iostream.h>

int a[50][50],i,j,k,n,x,y,per[50],tem[50],next[50];void print();int smallest();void main(){

cout<<"enter the no. of nodes "; cin>>n; cout<<"\nenter the weights.enter 1000 if no direct link exist\n"; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(i==j) a[i][j]=0; else { cout<<"\n"<<i<<"-"<<j<<": "; cin>>a[i][j]; } } } cout<<"\n Enter the node for which routing table is to be generated"; cin>>y; for(i=1;i<=n;i++) { per[i]=1000; tem[i]=1000; next[i]=0; } per[y]=0; for(i=1;i<=n;i++) { if(y!=i) { tem[i]=a[y][i]; } } for(k=1;k<n;k++) { x=smallest(); if(x==y) break; cout<<x; per[x]=tem[x]; for(j=1;j<=n;j++) { if((a[x][j]+per[x])<tem[j]&&j!=y&&j!=x&&per[j]==1000)

Page 19: Advanced Computer Networks Practical File

{ tem[j]=a[x][j]+per[x]; next[j]=x; }}tem[x]=1000;

} print(); } int smallest() { int temp=tem[1],z=1; for(i=1;i<=n;i++) { if(tem[i]<temp) {temp=tem[i]; z=i; } } return(z); } void print() { cout<<"\nthe routing table for node"<<y<<":\n"; cout<<"To\tCost\tNext\n"; for(j=1;j<=n;j++) { cout<<j<<"\t"<<per[j]<<"\t"<<next[j]<<"\n"; }}

OUTPUT

Page 20: Advanced Computer Networks Practical File

enter the no. of nodes 3

enter the weights.enter 1000 if no direct link exist

1-2:4

1-3:3

2-1:2

2-3:5

3-1:1

3-2:3

Enter the node for which table has to be generated2

the routing table for node2

1 3

To Cost Next

1 2 0

2 0 0

3 5 0

enter the no. of nodes

5.TO IMPLEMENT CLIENT/SERVER PROGRAM

THEORY:

Page 21: Advanced Computer Networks Practical File

Client-server computing or networking is a distributed application architecture that partitions tasks or work load between service providers (servers) and service requesters, called clients. Often clients and servers operate over a computer network on separate hardware. A server machine is a high-performance host that is running one or more server programs which share its resources with clients. A client does not share any of its resources, but requests a server's content or service function. Clients therefore initiate communication sessions with servers which await (listen to) incoming requests.

Client-server describes the relationship between two computer programs in which one program, the client program, makes a service request to another, the server program. Standard networked functions such as email exchange, web access and database access, are based on the client-server model. For example, a web browser is a client program at the user computer that may access information at any web server in the world. To check your bank account from your computer, a web browser client program in your computer forwards your request to a web server program at the bank. That program may in turn forward the request to its own database client program that sends a request to a database server at another bank computer to retrieve your account balance. The balance is returned to the bank database client, which in turn serves it back to the web browser client in your personal computer, which displays the information for you.

The client-server model has become one of the central ideas of network computing. Many business applications being written today use the client-server model. So do the Internet's main application protocols, such as HTTP, SMTP, Telnet, DNS. In marketing, the term has been used to distinguish distributed computing by smaller dispersed computers from the "monolithic" centralized computing of mainframe computers. But this distinction has largely disappeared as mainframes and their applications have also turned to the client-server model and become part of network computing.

Each instance of the client software can send data requests to one or more connected servers. In turn, the servers can accept these requests, process them, and return the requested information to the client. Although this concept can be applied for a variety of reasons to many different kinds of applications, the architecture remains fundamentally the same.

The most basic type of client-server architecture employs only two types of hosts: clients and servers. This type of architecture is sometimes referred to as two-tier. It allows devices to share files and resources. The two tier architecture means that the client acts as one tier and application in combination with server acts as another tier. Specific types of clients include web browsers, email clients, and online chat clients.

Specific types of servers include web servers, ftp servers, application servers, database servers, name servers, mail servers, file servers, print servers, and terminal servers. Most web services are also types of servers.

Page 22: Advanced Computer Networks Practical File

//package ServerClient;

import java.net.*;

Page 23: Advanced Computer Networks Practical File

public class Main {

public static int serverPort = 998;

public static int clientPort = 999;

public static int buffer_size = 1024;

public static DatagramSocket ds;

public static byte buffer[] = new byte[buffer_size];

public static void TheServer() throws Exception {

int pos = 0;

while(true) {

int c = System.in.read();

switch (c) {

case -1:

System.out.println("Server Quits....");

return;

case '\r':

break;

case '\n':

ds.send(new DatagramPacket(buffer,pos,InetAddress.getLocalHost(),clientPort));

pos = 0;

break;

default:

buffer[pos++] = (byte) c;

}

}

}

public static void TheClient () throws Exception {

while(true) {

Page 24: Advanced Computer Networks Practical File

DatagramPacket p = new DatagramPacket(buffer,buffer.length);

ds.receive(p);

System.out.println(new String(p.getData(),0,p.getLength()));

}

}

public static void main(String[] args) throws Exception {

// TODO code application logic here

if(args.length == 1) {

ds = new DatagramSocket (serverPort);

TheServer();

}

else {

ds = new DatagramSocket (clientPort);

TheClient();

}

}

}

6.CODE FOR ENCRYPTION AND DECRYPTION OF STRINGS

Page 25: Advanced Computer Networks Practical File

CRYPTOGRAPHY

Encryption is the process of converting ordinary information (plaintext) into unintelligible gibberish (i.e., cipher text). Decryption is the reverse, in other words, moving from the unintelligible cipher text back to plaintext. A cipher (or cipher) is a pair of algorithms which create the encryption and the reversing decryption. The detailed operation of a cipher is controlled both by the algorithm and in each instance by a key. This is a secret parameter (ideally known only to the communicants) for a specific message exchange context. Keys are important, as ciphers without variable keys can be trivially broken with only the knowledge of the cipher used and are therefore less than useful for most purposes.

In cryptography, code has a specific meaning. It means the replacement of a unit of plaintext (i.e., a meaningful word or phrase) with a code word (for example, apple pie replaces attack at dawn).

The main classical cipher types are transposition ciphers, which rearrange the order of letters in a message (e.g., 'hello world' becomes 'ehlol owrdl' in a trivially simple rearrangement scheme), and substitution ciphers, which systematically replace letters or groups of letters with other letters or groups of letters (e.g., 'fly at once' becomes 'gmz bu podf' by replacing each letter with the one following it in the Latin alphabet). Simple versions of either offered little confidentiality from enterprising opponents, and still don't. An early substitution cipher was the Caesar cipher, in which each letter in the plaintext was replaced by a letter some fixed number of positions further down the alphabet. It was named after Julius Caesar who is reported to have used it, with a shift of 3, to communicate with his generals during his military campaigns, just like EXCESS-3 code in boolean algebra.

Symmetric-key cryptography

Symmetric-key cryptography refers to encryption methods in which both the sender and receiver share the same key (or, less commonly, in which their keys are different, but related in an easily computable way). This was the only kind of encryption publicly known until June 1976.

The modern study of symmetric-key ciphers relates mainly to the study of block ciphers and stream ciphers and to their applications. A block cipher is, in a sense, a modern embodiment of Alberti's polyalphabetic cipher: block ciphers take as input a block of plaintext and a key, and output a block of ciphertext of the same size. Since messages are almost always longer than a single block, some method of knitting together successive blocks is required. Several have been developed, some with better security in one aspect or another than others. They are the modes of operation and must be carefully considered when using a block cipher in a cryptosystem.

The Data Encryption Standard (DES) and the Advanced Encryption Standard (AES) are block cipher designs which have been designated cryptography standards by the US government (though DES's designation was finally withdrawn after the AES was adopted). Despite its deprecation as an official standard, DES (especially its still-approved and much more secure triple-DES variant) remains quite popular; it is used across a wide range of applications, from ATM encryption to e-mail privacy and secure

Page 26: Advanced Computer Networks Practical File

remote access. Many other block ciphers have been designed and released, with considerable variation in quality. Many have been thoroughly broken.

Public-key cryptography

Symmetric-key cryptosystems use the same key for encryption and decryption of a message, though a message or group of messages may have a different key than others. A significant disadvantage of symmetric ciphers is the key management necessary to use them securely. Each distinct pair of communicating parties must, ideally, share a different key, and perhaps each ciphertext exchanged as well. The number of keys required increases as the square of the number of network members, which very quickly requires complex key management schemes to keep them all straight and secret. The difficulty of securely establishing a secret key between two communicating parties, when a secure channel doesn't already exist between them, also presents a chicken-and-egg problem which is a considerable practical obstacle for cryptography users in the real world.

In a groundbreaking 1976 paper, Whitfield Diffie and Martin Hellman proposed the notion of public-key (also, more generally, called asymmetric key) cryptography in which two different but mathematically related keys are used — a public key and a private key. A public key system is so constructed that calculation of one key (the 'private key') is computationally infeasible from the other (the 'public key'), even though they are necessarily related. Instead, both keys are generated secretly, as an interrelated pair.

In public-key cryptosystems, the public key may be freely distributed, while its paired private key must remain secret. The public key is typically used for encryption, while the private or secret key is used for decryption.

In addition to encryption, public-key cryptography can be used to implement digital signature schemes. A digital signature is reminiscent of an ordinary signature; they both have the characteristic that they are easy for a user to produce, but difficult for anyone else to forge. Digital signatures can also be permanently tied to the content of the message being signed; they cannot then be 'moved' from one document to another, for any attempt will be detectable. In digital signature schemes, there are two algorithms: one for signing, in which a secret key is used to process the message (or a hash of the message, or both), and one for verification, in which the matching public key is used with the message to check the validity of the signature. RSA and DSA are two of the most popular digital signature schemes. Digital signatures are central to the operation of public key infrastructures and many network security schemes (eg, SSL/TLS, many VPNs, etc).

Public-key algorithms are most often based on the computational complexity of "hard" problems, often from number theory. For example, the hardness of RSA is related to the integer factorization problem. More recently, elliptic curve cryptography has developed in which security is based on number theoretic problems involving elliptic

Page 27: Advanced Computer Networks Practical File

curves. Because of the difficulty of the underlying problems, most public-key algorithms involve operations such as modular multiplication and exponentiation, which are much more computationally expensive than the techniques used in most block ciphers, especially with typical key sizes. As a result, public-key cryptosystems are commonly hybrid cryptosystems, in which a fast high-quality symmetric-key encryption algorithm is used for the message itself, while the relevant symmetric key is sent with the message, but encrypted using a public-key algorithm. Similarly, hybrid signature schemes are often used, in which a cryptographic hash function is computed, and only the resulting hash is digitally signed.

#include<iostream.h>#include<stdio.h>#include<conio.h>void main(){char inputstr1[10],inputstr2[10], encrptstr[10],outptstr[10];int i, ch;cout<<"What do u want to do?"<<endl;cout<<"1) Encryption"<<endl;cout<<"2) Decryption"<<endl;cin>>ch;

if(ch==1){cout<<"Enter string to be encrypted(0-9 only)";gets(inputstr);

//code for encryptionfor(int j=0;j<10;j++)

{char c=inputstr1[j];switch(c)

{case '0':encrptstr[j]='a';

break;case '1':encrptstr[j]='b';

break;case '2':encrptstr[j]='c';

break;case '3':encrptstr[j]='d';

break;case '4':encrptstr[j]='e';

break;case '5':encrptstr[j]='f';

break;case '6':encrptstr[j]='g';

break;case '7':encrptstr[j]='h';

break;

Page 28: Advanced Computer Networks Practical File

case '8':encrptstr[j]='i';break;

case '9':encrptstr[j]='j';break;

}}

cout<<"encrypted string :";for(j=0;j<10;j++)cout<<encrptstr[j]<<endl;}

else if (ch==2){cout<<"Enter string to be decrypted(a to j only)";

gets(inputstr2);

//code to decrypt the stringfor(j=0;j<10;j++)

{char c=inputstr2[j];switch(c)

{case 'a':outptstr[j]='0';

break;case 'b':outptstr[j]='1';

break;case 'c':outptstr[j]='2';

break;case 'd':outptstr[j]='3';

break;case 'e':outptstr[j]='4';

break;case 'f':outptstr[j]='5';

break;case 'g':outptstr[j]='6';

break;case 'h':outptstr[j]='7';

break;case 'i':outptstr[j]='8';

break;case 'j':outptstr[j]='9';

break;}

}

cout<<"decrypted string :";for(j=0;j<10;j++)cout<<outptstr[j];}getch();}

Page 29: Advanced Computer Networks Practical File

OUTPUT

What do you want to do?

1. Encryption.2. Decryption

1

Enter the string to be encrypted(0-9 only)456

Encrypted string: efg

What do you want to do?

1. Encryption.2. Decryption

2

Enter the string to be decrypted(a-j only)abc

Encrypted string: 012

Page 30: Advanced Computer Networks Practical File

7.To IMPLEMENT DATA LINK LAYER-

THEORY

The Data Link Layer is Layer 2 of the seven-layer OSI model of computer networking. It corresponds to or is part of the link layer of the TCP/IP reference model.

The Data Link Layer is the protocol layer which transfers data between adjacent network nodes in a wide area network or between nodes on the same local area network segment. The Data Link Layer provides the functional and procedural means to transfer data between network entities and might provide the means to detect and possibly correct errors that may occur in the Physical Layer. Examples of data link protocols are Ethernet for local area networks (multi-node), the Point-to-Point Protocol (PPP), HDLC and ADCCP for point-to-point (dual-node) connections.

The Data Link Layer is concerned with local delivery of frames between devices on the same LAN. Data Link frames, as these protocol data units are called, do not cross the boundaries of a local network. Inter-network routing and global addressing are higher layer functions, allowing Data Link protocols to focus on local delivery, addressing, and media arbitration. In this way, the Data Link layer is analogous to a neighborhood traffic cop; it endeavors to arbitrate between parties contending for access to a medium.

When devices attempt to use a medium simultaneously, frame collisions occur. Data Link protocols specify how devices detect and recover from such collisions, but it does not prevent them from happening.

Delivery of frames by layer 2 devices is effected through the use of unambiguous hardware addresses. A frame's header contains source and destination addresses that indicate which device originated the frame and which device is expected to receive and process it. In contrast to the hierarchical and routable addresses of the network layer, layer 2 addresses are flat, meaning that no part of the address can be used to identify the logical or physical group to which the address belongs.

The data link thus provides data transfer across the physical link. That transfer can be reliable or unreliable; many data link protocols do not have acknowledgments of successful frame reception and acceptance, and some data link protocols might not even have any form of checksum to check for transmission errors. In those cases, higher-level protocols must provide flow control, error checking, and acknowledgments and retransmission.

Within the semantics of the OSI network architecture, the Data Link Layer protocols respond to service requests from the Network Layer and they perform their function by issuing service requests to the Physical Layer.

Page 31: Advanced Computer Networks Practical File

#include<stdio.h>#include<conio.h>void main(){ char st[100]; int arr[25][8]; int i=0,n=0,m=0,j; clrscr(); printf("\n\n Enter the message to be sent (string of bits not more than 12 bytes):\n\n "); gets(st); printf("\n\n\n The following packets (with header and trailer) will be sent:\n\n"); while(st[i]!='\0') { arr[m][n++]='1'; arr[m][n++]='0'; for(j=i;j<i+4 && st[j]!='\0';j++)

arr[m][n++]=st[j]; arr[m][n++]='1'; arr[m++][n]='\0'; n=0; i=j; } for(i=0;i<m;i++) { printf("\n Packet %d : ",i+1); for(j=0;arr[i][j]!='\0';j++)

printf("%c",arr[i][j]); } getch();}

Page 32: Advanced Computer Networks Practical File

OUTPUTEnter the message to be sent(string of bits not more than 12 bytes):

11111111111

The following packets (with header and trailor) will be sent:

Packet1 :1011111

Packet1 :1011111

Packet1 :101111


Recommended