NS Lab Final
NS Lab Final
8 Implementation of Data
Encryption and Decryption using
RSA Algorithm(Rivest, Shamir and
Adleman)
9 Implementation Client Server
model using FTP Protocol
AIM:
Write a program for Datalink layer framing methods by Bit Stuffing using C-
program.
APPARATUS REQUIERD:
C -editor
Standalone desktop.
PROCEDURE:
1. Start the program.
2. Open C-editor.
3. Type the C program.
4. Save the program with file name ext .c
5. Run the program.
6. If any error occurs in the program correct the error and run it again.
7. Enter the data of 4 bit size message bit.
8. Check the entered data.
9. Stop the program.
PROGRAM FOR BIT STUFFING METHOD:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void charc(void);
void main()
{
int choice;
while(1)
{
printf("\n\n\n1.character stuffing"); printf("\n\n2.exit");
printf("\n\n\n enter choice"); scanf("%d",& choice);
printf("%d", choice); if(choice>2)
printf("\n\n invalid option. .. please renter");
switch(choice)
{
case 1:
charc ();
break;
case 2:
exit(0);
}
}
}
void charc(void)
{
char c[50],d[50],t[50];
int i,m,j;
clrscr();
printf("enter the number of characters\n");
scanf("%d",&m);
printf("\n enter the characters\n");
for(i=0;i<m+1;i++)
scanf("%c",&c[i]);
printf("\n original data\n");
for(i=0;i<m+1;i++)
printf("%c",c[i]);
d[0]='d';
d[1]='l';
d[2]='e';
d[3]='s';
d[4]='t';
d[5]='x';
for(i=0,j=6;i<m+1;i++,j++)
{
if((c[i]=='d'&&c[i+1]=='l'&& c[i+2]=='e'))
{
d[j]='d';
j++;
d[j]='l';
j++;
d[j]='e';
j++;
m=m+3;
}
d[j]=c[i];
}
m=m+6;
m++;
d[m]='d';
m++;
d[m]='l';
m++;
d[m]='e';
m++;
d[m]='e';
m++;
d[m]='t';
m++;
d[m]='x';
m++;
printf("\n\n transmitted data: \n");
for(i=0;i<m; i ++)
{
printf ("%c",d[i]);
}
for(i=6,j=0;i<m-6;i++,j++)
{
if(d[i]=='d'&&d[i+1]=='l'&&d[i+2]=='e'&&d[i+3]=='d'&&d[i+4]=='l'&&d[i+5]=='e')
i=i+3;
t[j]=d[i];
}
printf("\n\n received data:");
for(i=0;i<j; i++)
{
printf("%c", t[i]);
}
}
SAMPLE OUTPUT:
RESULT:
Thus the program for implementation of a data link control for bit stuffing
method is executed and output is verified successfully.
EX.NO:1B IMPLEMENTATION OF DATALINK LAYER FRAMING METHODS
DATE: CHARACTER STUFFING
AIM:
Write a program for Datalink layer framing methods by Character Stuffing using C-
program.
APPARATUS REQUIERD:
C -editor
Standalone desktop.
PROCEDURE:
1. Start the program.
2. Open C-editor.
3. Type the C program.
4. Save the program with file name ext .c
5. Run the program.
6. If any error occurs in the program correct the error and run it again.
7. Enter the data of 4 bit size message bit.
8. Check the entered data.
9. Stop the program.
PROGRAM FOR CHARACTER STUFFING METHOD:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
void main() {
int i = 0, j = 0, n, pos;
char a[20], b[50], ch;
printf("Enter string\n");
scanf("%s", & a);
n = strlen(a);
printf("Enter position\n");
scanf("%d", & pos);
if (pos > n) {
printf("invalid position, Enter again :");
scanf("%d", & pos);
}
printf("Enter the character\n");
ch = getche();
b[0] = 'd';
b[1] = 'l';
b[2] = 'e';
b[3] = 's';
b[4] = 't';
b[5] = 'x';
j = 6;
while (i < n) {
if (i == pos - 1) {
b[j] = 'd';
b[j + 1] = 'l';
b[j + 2] = 'e';
b[j + 3] = ch;
b[j + 4] = 'd';
b[j + 5] = 'l';
b[j + 6] = 'e';
j = j + 7;
}
if (a[i] == 'd' && a[i + 1] == 'l' && a[i + 2] == 'e') {
b[j] = 'd';
b[j + 1] = 'l';
b[j + 2] = 'e';
j = j + 3;
}
b[j] = a[i];
i++;
j++;
}
b[j] = 'd';
b[j + 1] = 'l';
b[j + 2] = 'e';
b[j + 3] = 'e';
b[j + 4] = 't';
b[j + 5] = 'x';
b[j + 6] = '\0';
printf("\nframe after stuffing:\n");
printf("%s", b);
}
SAMPLE OUTPUT:
RESULT:
Thus the program for implementation of a data link control for character
stuffing method is executed and output is verified successfully.
EX.NO:2A IMPLEMENTATION OF ERROR DETECTION / ERROR
DATE: CORRECTION TECHNIQUES - LRC
AIM:
Write a program for Error Detection and Error Correction by LRC method using C-
program.
APPARATUS REQUIERD:
C -editor
Standalone desktop.
PROCEDURE:
1. Start the program.
2. Open C-editor.
3. Type the C program.
4. Save the program with file name ext .c
5. Run the program.
6. If any error occurs in the program correct the error and run it again.
7. Enter the data of 4 bit size message bit.
8. Check the entered data.
9. Stop the program.
PROGRAM FOR LRC METHOD:
#include<stdio.h>
#include<conio.h>
int binary(int);
void parity(int [],int []);
int arr[8],arr1[8],parityarr[8];
char chr;
int go,temp,temp1,i;
void main()
{ char chr1;
clrscr();
go=0;
Sender:
if(go==0)
printf("Enter Data : \n");
printf("\nEnter a character : ");
scanf("%c %c",&chr,&chr1);
temp=chr;
binary(temp);
printf("\n\nAscii value is : %d\n",temp);
printf("\nBinary Form : ");
for(i=7;i>=0;i--)
{
arr1[i]=arr[i];
printf("%d ",arr[i]);
}
printf("\n");
temp1=chr1;
binary(temp1);
printf("\n\nAscii value is : %d\n",temp1);
printf("\nBinary Form : ");
for(i=7;i>=0;i--)
{
printf("%d ",arr[i]);
}
parity(arr,arr1);
for(i=7;i>=0;i--)
{
arr[i]=0;
arr1[i]=0;
}
getch();
}
int binary(int x)
{
int rem;
int ctr=0,i=1;
do
{
rem=x%2;
arr[i]=rem;
if(rem==1)
{
ctr++;
}
x=x/2;
i++;
}
while(x!=0);
if(ctr%2==0)
{
arr[0]=0;
}
else
{
arr[0]=1;
}
return(0);
}
SAMPLING OUTPUT:
RESULT:
EX.NO:2B IMPLEMENTATION OF ERROR DETECTION / ERROR
DATE: CORRECTION TECHNIQUES-CRC
CCCCRCCRCCRC
Thus the Error detection and correction methods were executed and verified
successfully by LRC using c – editor.
AIM:
Write a program for Error Detection and Error Correction by CRC method using C-
program.
APPARATUS REQUIERD:
C -editor
Standalone desktop.
PROCEDURE:
1. Start the program.
2. Open C-editor.
3. Type the C program.
4. Save the program with file name ext .c
5. Run the program.
6. If any error occurs in the program correct the error and run it again.
7. Enter the data of 4 bit size message bit.
8. Check the entered data.
9. Stop the program.
PROGRAM FOR CRC:
#include <string.h>
#include <iostream.h>
int crc(char *ip, char *op, char *poly, int mode)
{
strcpy(op, ip);
if (mode) {
for (int i = 1; i < strlen(poly); i++)
strcat(op, "0");
}
/* Perform XOR on the msg with the selected polynomial */
for (int i = 0; i < strlen(ip); i++) {
if (op[i] == '1') {
for (int j = 0; j < strlen(poly); j++) {
if (op[i + j] == poly[j])
op[i + j] = '0';
else
op[i + j] = '1';
}
}
}
/* check for errors. return 0 if error detected */
for (i = 0; i < strlen(op); i++)
if (op[i] == '1')
return 0;
return 1;
}
int main()
{
char ip[50], op[50], recv[50], poly[50];
Thus the Error detection and correction methods were executed and verified
successfully by LRC using c – editor.
AIM:
Write a program for Error Detection and Error Correction by HAMMING method
using C- program.
APPARATUS REQUIERD:
C -editor
Standalone desktop.
PROCEDURE:
1. Start the program.
2. Open C-editor.
3. Type the C program.
4. Save the program with file name ext .c
5. Run the program.
6. If any error occurs in the program correct the error and run it again.
7. Enter the data of 4 bit size message bit.
8. Check the entered data.
9. Stop the program.
PROGRAM FOR HAMMING METHOD:
#include<stdio.h>
#include<conio.h>
void main() {
int data[7],rec[7],i,c1,c2,c3,c;
printf ("this works for message of 4bits in size \n enter message bit one by one: ");
scanf ("%d %d %d %d",& data[0],&data[1],&data[2],&data[4]);
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("\n the encoded bits are given below: \n");
for (i=0;i<7;i++) {
printf("%d ",data[i]);
}
printf("\n enter the received data bits one by one: ");
for (i=0;i<7;i++) {
scanf("%d",& rec[i]);
}
c1=rec[6]^rec[4]^rec[2]^rec[0];
c2=rec[5]^rec[4]^rec[1]^rec[0];
c3=rec[3]^rec[2]^rec[1]^rec[0];
c=c3*4+c2*2+c1 ;
if(c==0) {
printf ("\n congratulations there is no error: ");
} else {
printf("\n error on the position: %d\n the correct message is \n",c);
if(rec[7-c]==0)
rec[7-c]=1;
else
rec[7-c]=0;
for (i=0;i<7;i++) {
}
}
getch();
printf("%d ",rec[i]);
}
SAMPLE OUTPUT:
RESULT:
Thus the Error detection and correction methods were executed and verified
successfully by HAMMING using c – editor.
EX.NO:3 IMPLEMENTATION OF STOP AND WAIT & SLIDING WINDOEW
DATE: WINDOW
AIM:
To write a program for talk commands using socket programming to send and receive
message from client and server using connection oriented service.
APPARATUS REQUIERD:
JDK TOOLKIT 5.0
Standalone desktop
PROCEDURE:
Server:
1. Start the program.
2. Create server and client sockets.
3. Use input streams to get the message from user.
4. Use output stream to send message to the client.
5. Wait for client to display this message and write a new one to be displayed by the
server.
6. Display message given at client using input streams read from socket.
7. If in the message given by server or client, the word “end” is encountered, exit both
the programs.
8. Stop the program.
Client:
1. Start the program.
2. Create a client socket that connects to the required host and port.
3. Using input streams read message given by server and print it.
4. Using input streams, get message from user to be given to the server.
5. Use output streams to write message to the server.
6. Stop the program
Sender() {
}
public void run() {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
System.out.println("Waiting for Connection. .. ");
sender = new Socket("localhost", 2004);
sequence = 0;
out = new ObjectOutputStream(sender.getOutputStream());
out.flush();
in = new ObjectInputStream(sender.getInputStream());
str = (String) in.readObject();
System.out.println("reciver > " + str);
System.out.println("Enter the data to send. .. ");
packet = br.readLine();
n = packet.length();
do {
try {
if (i < n) {
msg = String.valueOf(sequence);
msg = msg.concat(packet.substring(i, i + 1));
} else if (i == n) {
msg = "end";
out.writeObject(msg);
break;
}
out.writeObject(msg);
sequence = (sequence == 0) ? 1 : 0;
out.flush();
System.out.println("data sent>" + msg);
ack = (String) in.readObject();
System.out.println("waiting for ack. ... \n\n");
if (ack.equals(String.valueOf(sequence))) {
i++;
System.out.println("receiver > "
+ " packet recieved\n\n");
} else {
System.out.println("Time out resending data ... \n\
n");
sequence = (sequence == 0) ? 1 : 0;
}
} catch (Exception e) {
}
} while (i < n + 1);
System.out.println("All data sent. exiting.");
} catch (Exception e) {
} finally {
try {
in.close();
out.close();
sender.close();
} catch (Exception e) {
}
}
}
public static void main(String args[]) {
Sender s = new Sender();
s.run();
}
}
RECEIVER:
import java.io.*;
import java.net.*;
Reciever() {
}
AIM:
Write a program in Java to implement Go Back N algorithm. The Program sends the
frames from the Client to the Server with checking for missing frames via sending an
acknowledgement.
APPARATUS REQUIERD:
JDK TOOLKIT 5.0
Standalone desktop
PROCEDURE:
Server:
1. Start the program.
2. Create server and client sockets.
3. Use input streams to get the message from user.
4. Use output stream to send message to the client.
5. Wait for client to display this message and write a new one to be displayed by the
server.
6. Display message given at client using input streams read from socket.
7. If in the message given by server or client, the word “end” is encountered, exit
both the programs.
8. Stop the program.
Client:
1. Start the program.
2. Create a client socket that connects to the required host and port.
3. Using input streams read message given by server and print it.
4. Using input streams, get message from user to be given to the server.
5. Use output streams to write message to the server.
6. Stop the program
PROGRAM FOR GO BACK-N AND SELECTIVE REPEAT PROTOCOL:
SENDER:
import java.net.*;
import java.io.*;
RECEIVER:
import java.net.*;
import java.io.*;
class SlideReceiver {
public static void main(String a[]) throws Exception {
Socket s = new Socket(InetAddress.getLocalHost(), 10);
DataInputStream in = new DataInputStream(s.getInputStream());
PrintStream p = new PrintStream(s.getOutputStream());
int i = 0, rptr = -1, nf, rws = 8;
String rbuf[] = new String[8];
String ch;
System.out.println();
do {
nf = Integer.parseInt(in.readLine());
if (nf <= rws - 1) {
for (i = 1; i <= nf; i++) {
rptr = ++rptr % 8;
rbuf[rptr] = in.readLine();
System.out.println("The received Frame " + rptr + " is : "
+ rbuf[rptr]);
}
rws -= nf;
System.out.println("\nAcknowledgment sent\n");
p.println(rptr + 1);
rws += nf;
} else
break;
ch = in.readLine();
} while (ch.equals("yes"));
}
}
SENDER OUTPUT:
CLIENT OUTPUT:
Enter the value of m : 7
Enter no. of frames to be sent:5
Enter data for frame no 0 => 1
Enter data for frame no 1 => 2
Enter data for frame no 2 => 3
Enter data for frame no 3 => 4
Enter data for frame no 4 => 5
Connected with server.
|0||1||2||3||4|
Sending frame:0
Acknowledgement of frame no 0 recieved.
Sending frame:1
Sending frame:2
Sending frame:3
Sending frame:4
Sending frame:5
SERVER OUTPUT:
Server established. Client is now connected. |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|| 32||33||34||35||36||37||38||39||40||41||42||43||44||45||46||47||
48||49||50||51||52||53||54||55||56||57||58||59||60|| 61||62||63||64||65||66||67||68||69||70||71||72||73||74||75||76||
77||78||79||80||81||82||83||84||85||86||87||88||89|| 90||91||92||93||94||95||96||97||98||99||100||101||102||103||
104||105||106||107||108||109||110||111||112||113|| 114||115||116||117||118||119||120||121||122||123||124||
125||126||0|
Frame 0 recieved Data:0 Acknowledgement sent
|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||32||
33||34||35||36||37||38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||56||57||58||59||60||61||
62||63||64||65||66||67||68||69||70||71||72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||89||90||
91||92||93||94||95||96||97||98||99||100||101||102||103||104||105||106||107||108||109||110||111||112||113||114||
115||116||117||118||119||120||121||122||123||124||125||126||0||1|
Frame 1 recieved Data:1 Error found.
Acknowledgement not sent.
|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||32||33||
34||35||36||37||38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||56||57||58||59||60||61||62||
63||64||65||66||67||68||69||70||71||72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||89||90||91||
92||93||94||95||96||97||98||99||100||101||102||103||104||105||106||107||108||109||110||111||112||113||114||
115||116||117||118||119||120||121||122||123||124||125||126||0||1||2|
Frames received not in correct order
Expected farme:1 Received frame no :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||32||33||
34||35||36||37||38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||56||57||58||59||60||61||62||
63||64||65||66||67||68||69||70||71||72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||89||90||91||
92||93||94||95||96||97||98||99||100||101||102||103||104||105||106||107||108||109||110||111||112||113||114||
115||116||117||118||119||120||121||122||123||124||125||126||0||1||2||3|
Frames received not in correct order
Expected farme:1 Received frame no :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||32||33||34||
35||36||37||38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||56||57||58||59||60||61||62||63||
64||65||66||67||68||69||70||71||72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||89||90||91||92||
93||94||95||96||97||98||99||100||101||102||103||104||105||106||107||108||109||110||111||112||113||114||115||
116||117||118||119||120||121||122||123||124||125||126||0||1||2||3||4|
Frames received not in correct order
Expected farme:1 Received frame no :4
RESULT:
Thus the Sliding Window Go Back N & SELECTIVE REPEAT PROTOCOL was
implemented and the parameters measured by using LAN-T simulation software.
EX.NO:5 IMPLEMENTATION OF DISTANCE VECTOR ROUTING ALGORITH,
DATE: ALGORITHM
AIM:
To simulate and study the Distance Vector routing algorithm using simulation.
SOFTWARE REQUIRED:
NS-2
THEORY:
Distance Vector Routing is one of the routing algorithm in a Wide Area Network for
computing shortest path between source and destination. The Router is one main devices used
in a wide area network. The main task of the router is Routing. It forms the routing table and
delivers the packets depending upon the routes in the tableeither directly or via an
intermediate devices. Each router initially has information about its all neighbors. Then this
information will be shared among nodes.
ALGORITHM:
1. Create a simulator object
2. Define different colors for different data flows
3. Open a nam trace file and define finish procedure then close the trace file, and
execute nam on trace file.
4. Create n number of nodes using for loop
5. Create duplex links between the nodes
6. Setup UDP Connection between n(0) and n(5)
7. Setup another UDP connection between n(1) and n(5)
8. Apply CBR Traffic over both UDP connections
9. Choose distance vector routing protocol to transmit data from sender to receiver.
10. Schedule events and run the program.
PROGRAM:
set ns [new Simulator]
set nr [open thro.tr w]
$ns trace-all $nr
set nf [open thro.nam w]
$ns namtrace-all
$nf proc finish { }
{ global ns nr nf
$ns flush-trace close
$nf close
$nr exec nam thro.nam &
exit 0
}
for { set i 0 } { $i < 12} { incr i 1 } {
set n($i) [$ns node]}
for {set i 0} {$i < 8} {incr i} {
Thus the Distance vector Routing Algorithm was Simulated and studied.
AIM:
To simulate and study the link state routing algorithm using simulation.
SOFTWARE
REQUIRE
D: NS-2
THEORY:
In link state routing, each router shares its knowledge of its neighborhood with every
other router in the internet work. (i) Knowledge about Neighborhood: Instead of
sending its entire routing table a router sends info about its neighborhood only. (ii) To all
Routers: each router sends this information to every other router on the internet work
not just to its neighbor .It does so by a process called flooding. (iii)Information sharing
when there is a change: Each router sends out information about the neighbors when
there is change.
PROCEDURE:
The Dijkstra algorithm follows four steps to discover what is called the shortest path
tree(routing table) for each router:The algorithm begins to build the tree by identifying
its roots. The root router’s trees the router itself. The algorithm then attaches all nodes
that can be reached from the root. The algorithm compares the tree’s temporary arcs and
identifies the arc with the lowest cumulative cost. This arc and the node to which it
connects are now a permanent part of the shortest path tree. The algorithm examines the
database and identifies every node that can be reached from its chosen node. These
nodes and their arcs are added temporarily to the tree.
The last two steps are repeated until every node in the network has become a permanent
part of the tree.
ALGORITHM:
1. Create a simulator object
2. Define different colors for different data flows.
3. Open a nam trace file and define finish procedure then close the trace file, and
execute nam on trace file.
4. Create n number of nodes using for loop
5. Create duplex links between the nodes
6. Setup UDP Connection between n(0) and n(5)
7. Setup another UDP connection between n(1) and n(5)
8. Apply CBR Traffic over both UDP connections
9. Choose Link state routing protocol to transmit data from sender to receiver.
10. Schedule events and run the program.
PROGRAM:
Thus the Link State Routing Algorithm was Simulated and studied.
EX.NO:7 DATA ENCRYPTION AND DECRYPTION USING DATA ENCRYPTION
DATE: STANDARD ALGORITHM
AIM:
To implement Data encryption and decryption
SOFTWARE REQUIREMENTS:
Turbo C software
THEORY:
In encryption, each letter position in the file text which is given in encrypt mode is changed
according to the ascending order of the key text. In decryption each letter position in the encrypted
file text is changed according to the ascending order of the key text.
ALGORITHM-ENCRYPTION
The resulting value will be the encrypted format (cipher text) of the plain text.
ALGORITHM-DECRYPTION
Get the text to be decrypted (cipher text) and key text. Find the length of the cipher text. For
i=1 to length of cipher text a. Find the binary equivalent of i th character of cipher text. b. Find the
binary equivalent of i th character of key text c. Find the XOR of above two values. The resulting value
will be the decrypted format (original plain text) of the cipher plain text.
PROGRAM
# include
#include
void main ( )
switch (s)
{ case 1: printf(“enter the key value:”);
scanf(“%d”, &k);
scanf(“%d”, &n);
if (c[i]>90) c[i]=c[i]-26;}
printf(“encrypted data”);
for (i=1;i<=n;i+ +)
printf(“%c”, c[i]);
break;
case 2: printf(“enter the key value:”);
scanf(“%d”, &k);
scanf(“%d”, &n);
break;
case 3: break;
getch ();
}
OUTPUT:
1. ENCRYPTION
2. DECRYPTION
AIM:
SOFTWARE REQUIREMENTS:
Turbo C software
THEORY:
In encryption, each letter position in the file text which is given in encrypt mode is changed
according to the ascending order of the key text. In decryption each letter position in the encrypted
file text is changed according to the ascending order of the key text.
ALGORITHM-ENCRYPTION
Get the text to be encrypted (plain text) and key text.
a. Find the length of the plain text.
b. For i=1 to length of plain text
c. Find the binary equivalent of i th character of plain text.
d. Find the binary equivalent of i th character of key text
e. Find the XOR of above two values.
The resulting value will be the encrypted format (cipher text) of the plain text.
ALGORITHM-DECRYPTION
Get the text to be decrypted (cipher text) and key text.
Find the length of the cipher text.
For i=1 to length of cipher text
a. Find the binary equivalent of i th character of cipher text.
b. Find the binary equivalent of i th character of key text
c. Find the XOR of above two values.
The resulting value will be the decrypted format (original plain text) of the cipher plain text
PROGRAM FOR DATA ENCRYPTION AND DECRYPTION USING RSA:
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.security.*;
import java.util.Base64;
keyPairGenerator.initialize(2048, secureRandom);
KeyPair pair = keyPairGenerator.generateKeyPair();
}
OUTPUT:
Enter the data to encrypt. ..
goodday
encrypted message =
SmpWNbMRWNDSO3x2pbGBAIZSFZn43gFXbpo4FNp9pzA7TbpvxoL/W5fJ1p+3wRfkJI/
rriHDQSyeNMEi9Itx2q0ZCI0BimbshggAgBw4ot20tE3Fkjl4gRzOuOTav3B+bGQUeXZMnO6z/
eiFN7tj5NkY8lgq6WZm+8DxGUcvEzkSv8w53EhXvc0wkjdYEhEsS1FEfsTuMOKpFsM6Q24dARTe
VpRwxM58Iw8iLVzg7knrYCSf5mrHomr2yoImG528i3gAk2ZsYByHB0dtbOEBRtkO74zexQyoItr
TuGqAwnRmRASvyPrWqmp3i2UBn9KQTfiGO70s7JUKWA+y01F1Yw==
decrypted message = goodday
RESULT:
Thus the Data Encryption and Decryption using RSA algorithm was studied.
EX.NO:9 IMPLEMENTATION OF CLIENT SERVER MODEL USING
DATE: FTP PROTOCOL
AIM:
To implement the client server model using FTP protocol.
APPARATUS REQUIRED:
Java outlook
Personal computer
ALGORITHM:
1. Enter local passive mode for data connection.
2. Set file type to be transferred to binary.
3. Create an InputStream for the local file.
4. Construct path of the remote file on the server. The path can be absolute or relative to
the current working directory.
5. Call one of the storeXXX()methods to begin file transfer. There are two scenario.
6. Using an InputStream-based approach: this is the simplest way, since we let the
system does the ins and outs. There is no additional code, just passing the InputStream
object into the appropriate method, such as storeFile(String remote, InputStream
local) method.
7. Using an OutputStream-based approach: this is more complex way, but more control.
Typically we have to write some code that reads bytes from the InputStream of the
local file and writes those bytes into the OutputStream which is returned by the
storeXXX() method, such as storeFileStream(String remote) method.
8. Close the opened InputStream and OutputStream.
9. Call completePendingCommand() method to complete transaction.
10. Logout and disconnect from the server.
PROGRAM FOR CLIENT SERVER MODEL USING FTP PROTOCOL:
CLIENT:
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.Socket;
public class FileClient {
public static void main(String[] args) throws Exception {
sock.close();
}
do {
bytesRead = is.read(mybytearray, current,
(mybytearray.length - current));
if (bytesRead >= 0)
current += bytesRead;
} while (bytesRead > -1);
bos.write(mybytearray, 0, current);
bos.flush();
bos.close();
System.out.println("Received and saved file as " + outputFilePath);
}
}
SERVER:
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
RECEIVER:
Connecting to the server
Received and saved file as C:/File_Inputs/FTP_Output.txt
RESULT:
Thus the Client sever model using FTP protocol was studied.
EX.NO:10 NETWORK TOPOLOGY
DATE: BUS TOPOLOGY
AIM:
To create scenario and study the performance of token bus protocol through
simulation.
HARDWARE / SOFTWARE REQUIREMENTS:
NS-2
THEORY:
Token bus is a LAN protocol operating in the MAC layer. Token bus is standardized
as per IEEE 802.4. Token bus can operate at speeds of 5Mbps, 10 Mbps and 20 Mbps. The
operation of token bus is as follows: Unlike token ring in token bus the ring topology is
virtually created and maintained by the protocol. A node can receive data even if it is not part
of the virtual ring, a node joins the virtual ring only if it has data to transmit. In token bus
data is transmitted to the destination node only where as other control frames is hop to hop.
After each data transmission there is a solicit_successsor control frame transmitted which
reduces the performance of the protocol.
ALGORITHM:
1. Create a simulator object
2. Define different colors for different data flows
3. Open a nam trace file and define finish procedure then close the trace file, and
execute nam on trace file.
4. Create five nodes that forms a network numbered from 0 to 4
5. Create duplex links between the nodes and add Orientation to the nodes for setting
a LAN topology
6. Setup TCP Connection between n(1) and n(3)
7. Apply CBR Traffic over TCP.
8. Schedule events and run the program.
PROGRAM:
proc finish {} {
global ns nf
$ns flush-trace
exit 0
#Create a TCP Sink agent (a traffic sink) for TCP and attach it to node n3
set sink0 [new Agent/TCPSink]
$ns run
OUTPUT:
RESULT:
Thus the Bus Topology was Simulated and studied.
AIM:
To create scenario and study the performance of token star protocol through
simulation.
HARDWARE / SOFTWARE REQUIREMENTS:
NS-2
THEORY:
Token ring is a LAN protocol operating in the MAC layer. Token ring is standardized
as per IEEE 802.5. Token ring can operate at speeds of 4mbps and 16 mbps. The operation of
token ring is as follows: When there is no traffic on the network a simple 3-byte token
circulates the ring. If the token is free (no reserved by a station of higher priority as explained
later) then the station may seize the token and start sending the data frame. As the frame
travels around the ring ach station examines the destination address and is either forwarded
(if the recipient is another node) or copied. After copying4 bits of the last byte is changed.
This packet then continues around the ring till it reaches the originating station. After the
frame makes a round trip the sender receives the frame and releases a new token onto the
ring.
ALGORITHM:
1. Create a simulator object
2. Define different colors for different data flows
3. Open a nam trace file and define finish procedure then close the trace file, and
execute nam on trace
file.
4. Create five nodes that forms a network numbered from 0 to 4
5. Create duplex links between the nodes to form a Ring Topology.
6. Setup TCP Connection between n(1) and n(3)
7. Apply CBR Traffic over TCP
8. Schedule events and run the program
PROGRAM:
global ns nf
$ns flush-trace
close $nf
#Executenam on the trace file
exit0
$ns attach-agent
$n1 $tcp0
#Create a TCP Sink agent (a traffic sink) for TCP and attach it to node n3
set sink0 [new Agent/TCPSink]
$ns run
OUTPUT:
RESULT:
Thus the Star Topology was Simulated and studied.
EX.NO:10 NETWORK TOPOLOGY
DATE: RING TOPOLOGY
AIM:
To create scenario and study the performance of token ring protocol through
simulation.
HARDWARE / SOFTWARE REQUIREMENTS:
NS-2
THEORY:
Token bus is a LAN protocol operating in the MAC layer. Token ring is standardized
as per IEEE 802.4. Token bus can operate at speeds of 5Mbps, 10 Mbps and 20 Mbps. The
operation of token bus is as follows: Unlike token ring in token bus the ring topology is
virtually created and maintained by the protocol. A node can receive data even if it is not part
of the virtual ring, a node joins the virtual ring only if it has data to transmit. In token bus
data is transmitted to the destination node only where as other control frames is hop to hop.
After each data transmission there is a solicit_successsor control frame transmitted which
reduces the performance of the protocol.
ALGORITHM:
1. Create a simulator object
2. Define different colors for different data flows
3. Open a name trace file and define finish procedure then close the trace file, and
execute nam on trace file.
4. Create five nodes that forms a network numbered from 0 to 4
5. Create duplex links between the nodes and add Orientation to the nodes for setting
a LAN topology
6. Setup TCP Connection between n(1) and n(3)
7. Apply CBR Traffic over TCP.
8. Schedule events and run the program.
PROGRAM:
#Create a simulator object
$ns namtrace-all
global ns nf
$ns flush-trace
close $nf
exit 0
#Create a TCP Sink agent (a traffic sink) for TCP and attach it to node n3 set
$ns run
OUTPUT:
RESULT:
Thus the Ring Topology was Simulated and studied.
EX.NO:11 PERFORMANCE ANALYSIS OF CSMA/CA AND CSMA/CD PROTOCOLS
DATE:
AIM:
To create scenario and study the performance of CSMA / CD protocol through simulation.
SOFTWARE REQUIREMENTS:
Ns-2
THEORY:
Ethernet is a LAN (Local area Network) protocol operating at the MAC (Medium
Access Control) layer. Ethernet has been standardized as per IEEE 802.3. The underlying
protocol in Ethernet is known as the CSMA /CD – Carrier Sense Multiple Access / Collision
Detection. The working of the Ethernet protocol is as explained below, A node which has data
to transmit senses the channel. If the channel is idle then, the data is transmitted. If the
channel is busy then, the station defers transmission until the channel is sensed to be idle and
then immediately transmitted. If more than one node starts data transmission at the same
time, the data collides. This collision is heard by the transmitting nodes which enter into
contention phase. The contending nodes resolve contention using an algorithm called
Truncated binary exponential back off.
ALGORITHM:
1. Create a simulator object
2. Define different colors for different data flows
3. Open a nam trace file and define finish procedure then close the trace file, and
execute nam on trace file.
4. Create six nodes that forms a network numbered from 0 to 5
5. Create duplex links between the nodes and add Orientation to the nodes for setting
a LAN topology.
6. Setup TCP Connection between n(0) and n(4)
7. Apply FTP Traffic over TCP
8. Setup UDP Connection between n(1) and n(5)
9. Apply CBR Traffic over UDP.
10. Apply CSMA/CA and CSMA/CD mechanisms and study their performance
11. Schedule events and run the program.
PROGRAM:
CSMA/CA
proc finish {} {
$ns flush-trace
close $file1
close $file2
exit 0
39
}
#Create six nodes
set lan [$ns newLan "$n3 $n4 $n5" 0.5Mb 40ms LL Queue/DropTail MAC/Csma/Ca Channel]
global ns
# PPP
$ns at 125.0 "finish"
$ns run
OUTPUT:
CSMA/CD
proc finish {} {
$ns flush-trace
close $file1
close $file2
exec nam out.nam &
exit 0
set lan [$ns newLan "$n3 $n4 $n5" 0.5Mb 40ms LL Queue/DropTail MAC/Csma/Cd Channel]
Setup a TCP connection
global ns
set time 0.1
# PPP
$ns run
OUTPUT
RESULT: