Networks and Security Lab Manual
Networks and Security Lab Manual
Therkutheru, Melur.
DEPARTMENT OF CSE
RECORD
STUDENT NAME:
REGISTER.NO:
YEAR/SEM:
VAIGAI COLLEGE OF ENGINEERING
MADURAI – 625 122
https://vaigai.org/
AIM:-
To implement the data link layer of bit stuffing.
Software Required:-
Turbo C-programming.
Algorithm:-
STEP-1 - Start.
STEP-2 - Initialize the array for transmitted stream with the special bit
pattern 0111 1110 which indicates the beginning of the frame.
STEP-4 - Check for five consecutive ones and if they occur, stuff a bit 0.
STEP-5 - Display the data transmitted as it appears on the data line after
appending 0111 1110 at the end.
1
PROCEDURE:-
Bit stuffing refers to the insertion of one or more bits into a data
transmission as a way to provide signaling information to a receiver. The
receiver knows how to detect, remove or disregard the stuffed bits.Bit stuffing
is a process of inserting an extra bit as 0, once the frame sequence encountered
5 consecutive 1's.During the traversal of the array, 5 consecutive 1’s are
encountered after the 4th index of the given array. Hence, a zero bit has been
inserted into the stuffed array after the 4th index.If arr[i] is 1 then check for
the next 4 bits if they are set bits as well. If they are, then insert a 0 bit after
inserting all the 5 set bits into the array brr[].Otherwise, insert the value
of arr[i] into the array brr[].
PROGRAM:-
#include<stdio.h>
#include<string.h>
int main()
{
int x[20],y[30],i,j,k,count,n;
printf("Enter frame size: ");
scanf("%d",&n);
printf("Enter the frame in the form of 0 and 1: ");
for(i=0; i<n; i++)
scanf("%d",&x[i]);
i=0;
count=1; j=0;
while(i<n)
{
if(x[i]==1)
{
y[j]=x[i];
for(k=i+1; x[k]==1 && k<5; k++)
{
j++;
2
y[j]=x[k];
count++;
if(count==5)
{
j++;
y[j]=0
;
}
i=k;
}
}
else
{
y[j]=x[i];
}
i++
;
j++
;
}
printf("After Bit Stuffing: ");
for(i=0; i<j; i++)
printf("%d",y[i]);
return 0;
}
3
OUTPUT:-
Enter frame size:12
Enter the frame in the form of 0 and 1 :0 1 0 1 1 1 1 1 1 0 0 1
After Bit Stuffing :0101111101001
4
Implement The Data Link Layer Of Character Stuffing
AIM:-
To implement the data link layer of character stuffing.
Software Required:-
Turbo C-programming.
Algorithm:-
STEP-1 - Start.
STEP-6 - Stop.
Procedure:-
The character stuffing method gets around the problem of re
synchronization after an error by having each frame start and end with special
bytes. Character Stuffing / Byte Stuffing: Character stuffing or byte stuffing is
which an escape byte (ESC) is stuffed character stream before a flag byte in the
data.Since this can interfere with the framing, a technique called character
stuffing is used. The sender's data link layer inserts an ASCII DLE character just
before the DLE character in the data. The receiver's data link layer removes this
DLE before this data is given to the network layer. However character stuffing is
closely associated with 8-bit characters and this is a major hurdle in transmitting
arbitrary sized character.
5
Program:-
#include<stdio.h>
#include<string.h>
main()
{
char a[30], fs[50] = " ", t[3], sd, ed, x[3], s[3], d[3],
y[3]; int i, j, p = 0, q = 0;
clrscr();
printf("Enter characters to be stuffed:");
scanf("%s", a);
printf("\nEnter a character that represents starting delimiter:");
scanf(" %c", &sd);
printf("\nEnter a character that represents ending delimiter:");
scanf(" %c", &ed);
x[0] = s[0] = s[1] = sd;
x[1] = s[2] = '\0';
y[0] = d[0] = d[1] = ed;
d[2] = y[1] = '\0';
strcat(fs, x);
for(i = 0; i < strlen(a); i++)
{
t[0] = a[i];
t[1] = '\0';
if(t[0] == sd)
strcat(fs, s);
else if(t[0] ==
ed)
strcat(fs, d);
else
strcat(fs, t);
}
strcat(fs, y);
printf("\n After stuffing:%s", fs);
getch();
}
6
Output:-
Result:-
Thus the implementation of data link layer of bit stuffing and
character stuffing was verified sucessfully.
7
Implementation Of Error Detection & Correction CRC
AIM:-
To implement the error correction and detection by using the CRC technique.
Software Reqired:-
Turbo C-Programming.
Algorithm:-
STEP- 1 - Start.
STEP-2 - Load a 16-bit register with FFFF hex (all 1's). Call this the CRC
register.
STEP-3 - Exclusive OR the first eight-bit byte of the message with the low
order byte of the 16-bit CRC register.
STEP-4 - Shift the CRC register one bit to the right (toward the LSB),
zerofilling the MSB. Extract and examine the LSB.
STEP-6 -Repeat Steps 3 and 4 until eight shifts have been performed.
When this is done, a complete eight-bit byte will have been processed..
Program:-
#include<stdio.h>
char text[100];
char key[100];
char rem[100];
void crc()
{
int i,j;
int keylen,textlen;
char temp[100];
strcpy(temp,text);
keylen=strlen(key);
for(i=0;i<keylen-
1;i++)
strcat(temp,"0");
textlen=strlen(temp);
strncpy(rem,temp,keylen);
while(i!=textlen)
{
if(rem[0]=='0')
{
strcpy(rem,&rem[1]);
rem[keylen-
1]=temp[++i];
rem[keylen]='\0';
continue;
}
for(j=0;j<keylen;j++)
rem[j]=((rem[j]-'0')^(key[j]-
'0'))+'0';
}
}
main()
{
int i;
int choice;
while(1)
{
printf("\n1.find crc\t2.check crc\t3.exit crc\nyour choice\t");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter the input string\n");
scanf("%s",text);
printf("Enter the key\n");
scanf("%s",key);
crc();
printf("the transmitted message is %s\n",strcat(text,rem));
break;
case 2:
printf("Enter the input string\n");
scanf("%s",&text);
printf("Enter the key\n");
scanf("%s",key);
crc();
for(i=0;i<strlen(key)-
1;i++) if(rem[i]=='1')
break;
if(i==strlen(key)-
1)
printf("There is no error in the message\n");
else
printf("There is error in the message\n");
break;
case 3:
exit(0;
}
}
Output:-
1. find crc 2.check crc 3.exit
crc your choice 1
Enter the input string
110111
Enter the key
111
the transmitted message is 11011111
Result:-
Thus the implementation of error correction and detection technique CRC
was verified.
Implementation of Error Correction and Detection Technique
Hamming code
Aim:-
To implement the error correction and detection technique using hamming
code.
Software Required:-
Turbo C-Programming.
Algorithm:-
STEP-1 - Start.
STEP-2 - First write the bit positions starting from 1 in a binary form.
STEP-3 - Mark all the bit positions that are powers of two as parity bits.
STEP-4 - All other bit positions are for the data to be encoded using (3, 5,
6, 7, 9, 10 and 11, etc.)
Program:-
#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 \nenter 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("\nthe encoded bits are given below: \n");
for (i=0;i<7;i++) {
printf("%d ",data[i]);
}
printf("\nenter 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("\ncongratulations there is no error: ");
} else {
printf("\nerron on the postion: %d\nthe correct message is \n",c);
if(rec[7-c]==0)
rec[7-c]=1;
elserec[7-c]=0;
for (i=0;i<7;i++) {
printf("%d ",rec[i]);
}
}
getch();
}
Output:-
Result:-
Thus implementation of error detection and correction using
hamming code was verified.
Implementation of Error Detection & Correction LRC
AIM:-
To implement the error correction and detection by using the LRC technique.
Software Reqired:-
Turbo C-Programming.
Algorithm:-
STEP- 1 - Start.
STEP-2 - Add all bytes in the message, excluding the starting colon and
ending CRLF. Add them into an eight-bit field, so that carries will be discarded.
STEP-3 - Subtract the final field value from FF hex (all 1's), to produce
the ones-complement.
STEP-6 - Sender frame is send to the receiver and display to the receiver.
STEP-8 - Stop.
Procedure:-
The Longitudinal Redundancy Check (LRC) field is one byte, containing an
eight-bit binary value. The LRC value is calculated by the transmitting device,
which appends the LRC to the message. The receiving device recalculates an
LRC during receipt of the message, and compares the calculated value to the
actual value it received in the LRC field. If the two values are not equal, an error
results.The LRC is calculated by adding together successive eight-bit bytes in the
message, discarding any carries, then two's complementing the result. The LRC
is an eight-bit field, therefore each new addition of a character that would result in
a value higher than 255 decimal simply rolls over the field's value through zero.
Because there is no ninth bit, the carry is discarded automatically.
Program:-
#include<stdio.h>
#include<conio.h
>int binary(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)
temp=chr;
binary(temp);
for(i=7;i>=0;i--)
arr1[i]=arr[i];
printf("%d
",arr[i]);
printf("\n");
temp1=chr1;
binary(temp1);
printf("%d ",arr[i]);
}
parity(arr,arr1);
for(i=7;i>=0;i--
)
arr[i]=0;
arr1[i]=0
getch();
printf("\n\nLRC :\n");
for(i=7;i>=0;i--)
printf("%d ",arr[i]);
printf("\n");
for(i=7;i>=0;i--)
printf("%d ",arr1[i]);
}
printf("\n \n");
for(i=0;i<8;i++)
parityarr[i]=0;
parityarr[i]=1;
for(i=7;i>=0;i--)
printf("%d ",parityarr[i]);
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);
}
Output:-
Result:-
Thus the error detection and correction technique using LRC was verified.
Implementation of Stop & Wait - Sliding Window Protocols
Aim:-
To implement the stop and wait and sliding window protocols using c-
programming.
Software required:-
Turbo C-programming.
Algorithm:-
STEP-1 - Start.
STEP-6 - Sender frame is send to the receiver and display to the receiver.
STEP-8 - Receiver receives all the frames automatically and displays the
message.
STEP-10 - Stop.
1
Procedure:
Establish connection to the server. Send the frame to the receiver.If it
receive the acknowledgement and negative acknowledgement from the receiver.
If the receiver negative acknowledgement then once again send the frame to the
receiver.Close the sender side connection.Establish connection to the
server.Receive the frame from the receiver. Send acknowledgement and negative
acknowledgement from the receiver. Close the sender side connection.
Program:-
#include<stdio.h>
#include<stdlib.h>
#include<string.h
>int main()
{
int i, n, ch;
char input[20];
FILE *in;
randomize();
printf(“\n\t\t Stop and Wait Protocol \n”);
printf(“\n 1. Send \n2. Check
ACK\n3.EOT\n”); while(1)
{
printf(“Enter your
choice….”);scanf(“%d”,
&ch);
switch(ch)
{
case 1:
in = fopen(“data.txt”, “w”);
printf(“Enter the Data: “);
scanf(“%s”, input);
n = strlen(input);
for(i=0; i<n+1; i++)
fprintf(in, “%s”,
input); fclose(in);
printf(“——->Data
Sent\n”); break;
getch();
2
}
RECEVIER.C:-
#include<stdio.h>
#include<conio.h>
#include<string.h
> void main()
{
int i, n,;
char output[20];
FILE *out;
clrscr();
out=fopen(“data_parity.txt”, “r”);
fscanf(out, “%s”, output);
n = strlen(output);
for(i=0; i<n; i++)
if(output[i]==’1’)
one++;
if(one%2==0
)
{
printf(“Received Data has Even
Parity\n”); printf(“Data Accepted\n”);
}
else
{
printf(“Received Data has Odd Parity\n”);
printf(“Data Rejected\n”);
}
printf(“Received Data:
“);for(i=0;i<n-1; i++)
printf(“%c”, output[i];
fclose(out);
getch();
}
3
OUTPUT:-
4
Program:-
Sliding window
protocols:- #include<stdio.h>
#include<conio.h>
void main()
{
char sender[50],receiver[50];
int i,winsize;
clrscr();
printf("\n ENTER THE WINDOWS SIZE : ");
scanf("%d",&winsize);
printf("\n SENDER WINDOW IS EXPANDED
TO STORE MESSAGE ORWINDOW \n");
printf("\n ENTER THE DATA TO BE SENT: ");
fflush(stdin);
gets(sender);
for(i=0;i<winsize;i+
+)
receiver[i]=sender[i];
receiver[i]=NULL;
printf("\n MESSAGE SEND BY THE SENDER:\n");
puts(sender);
printf("\n WINDOW SIZE OF RECEIVER IS
EXPANDED\n"); printf("\n ACKNOWLEDGEMENT
FROM RECEIVER \n");
for(i=0;i<winsize;i++
); printf("\n
ACK:%d",i);
printf("\n MESSAGE RECEIVED BY RECEIVER IS : ");
puts(receiver);
printf("\n WINDOW SIZE OF RECEIVER IS SHRINKED \n");
getch();
}
5
Output:-
SENDER:
ForgetCode.com
EXPANDED ACKNOWLEDGEMENT
6
Result:-
Thus the C-programming using stop and wait and sliding window protocols
was implemented and verified successfully.
7
Implementation of Go-Back & Selective Repeat Protocols
Aim:-
To implement the go-back and selective repeat protocols by using C-
programming.
Software Required:-
Turbo C-Programming.
Algorithm:-
STEP-1 - Start.
STEP-2 - In Go-Back-N Protocol, if the sent frame are find suspected then all the
frames are re-transmitted from the lost packet to the last packet transmitted
STEP-3 - In selective Repeat protocol, only those frames are re-transmitted which
are found suspected.
STEP-5 - The size is half of the frame's maximum sequence number. For
example, if the sequence number is from 0–15, the window size will be 8.
STEP-7 -The size of the transmitting window determines the maximum number
of frames that can be sent.
STEP-8 - Stop.
Procedure:-
Go-Back-N is a data link layer protocol that uses a sliding window method
for reliable and sequential delivery of data frames. It is a case of sliding window
protocol having to send window size of N and receiving window size of 1.
Selective Repeat Protocol is also a data link layer protocol that uses sliding
window method for reliable delivery of data frames. Here, only the erroneous or
lost frames are retransmitted, while the good frames are received and buffered.
Program:-
Go Back N protocol
#include<stdio.h>
int main()
{
int windowsize,sent=0,ack,i;
printf("enter window size\n");
scanf("%d",&windowsize);
while(1)
{
for( i = 0; i < windowsize; i++)
{
printf("Frame %d has been transmitted.\n",sent);
sent++;
if(sent ==
windowsize)
break;
}
printf("\nPlease enter the last Acknowledgement received.\n");
scanf("%d",&ack);
if(ack ==
windowsize)
break;
else
sent = ack;
}
return 0;
}
Output:-
enter window size
8
Frame 0 has been transmitted.
Frame 1 has been transmitted.
Frame 2 has been transmitted.
Frame 3 has been transmitted.
Frame 4 has been transmitted.
Frame 5 has been transmitted.
Frame 6 has been transmitted.
Frame 7 has been transmitted.
Output:-
Result:-
Thus the implementation of go-back n and selective repeat protocols are
verified.
Implementation of Distance Vector Routing algorithm.
AIM:-
To implement the distance vector routing algorithm of bellman Ford.
Software Required:-
Turbo C-Programming.
Algorithm:-
STEP-1 - Start.
STEP-2 - The routers in the network start sharing their information with
the neighboring router in the network.
STEP-3 - After creating the separate local table this information is shared
with the neighboring node having a direct link.
STEP-5 - while creating a new routing table, only the distance vector
information sis hared that to its neighbor which has a direct link.
STEP-7 - Stop.
Procedure:-
As you can see in the above network all the link has been used. In the
routing table of A link AD and AB is used. In the routing table of B only
link BA and BC. In the routing table of C, only links CB and CD are used and in
D'srouting table only links DA and DC are used.
In this sense, we can also check which of the links can be used and which cannot.
In this way we find the shortest path using the distance vector routing algorithm.
Program:-
#include<stdio.h>
struct node
{
unsigned dist[20];
unsigned from[20];
}rt[10];
int main()
{
int costmat[20][20];
int nodes,i,j,k,count=0;
printf("\nEnter the number of nodes : ");
scanf("%d",&nodes);//Enter the nodes
printf("\nEnter the cost matrix :\n");
for(i=0;i<nodes;i++)
{
for(j=0;j<nodes;j++)
{
scanf("%d",&costmat[i][j])
;costmat[i][i]=0;
rt[i].dist[j]=costmat[i][j];
rt[i].from[j]=j;
}
}
do
{
count=0;
for(i=0;i<nodes;i++)
for(j=0;j<nodes;j++)
for(k=0;k<nodes;k++)
if(rt[i].dist[j]>costmat[i][k]+rt[k].dist[j])
{
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];
rt[i].from[j]=k;
count++;
}
}while(count!=0);
for(i=0;i<nodes;i++)
{
printf("\n\n For router %d\n",i+1);
for(j=0;j<nodes;j++)
{
printf("\t\nnode %d via %d Distance %d
",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}
printf("\n\n");
getch();
}
Output:-
Enter the number of nodes :
3
Enter the cost matrix :
027
201
710
For router 1
node 1 via 1 Distance 0
node 2 via 2 Distance 2
node 3 via 3 Distance 3
For router 2
node 1 via 1 Distance 2
node 2 via 2 Distance 0
node 3 via 3 Distance 1
For router 3
node 1 via 1 Distance 3
node 2 via 2 Distance 1
node 3 via 3 Distance 0
Result:-
Thus the implementation of Distance Vector Routing algorithm was
implemented and verified successfully.
Implementation of link state routing algorithm
AIM:-
To implement the link state routing algorith of open shortest path.
Software Required:-
Turbo C-Programming.
Algorithm:-
STEP-1 - Start.
STEP-2 - The currently known least cost path from A to its directly
attached neighbors, B, C, D are 2,5,1 respectively.
STEP-5 -In the above table, we observe that both E and B have the least
cost path in step 2. Let's consider the E vertex. Now, we determine the least cost
path of remaining vertices through E.
STEP-7 - Stop.
Procedure:-
Instead of sending its routing table, a router sends the information
about its neighborhood only. A router broadcast its identities and cost of the
directly attached links to other routers.Each router sends the information to every
other router on the internetwork except its neighbors. This process is known as
Flooding. Every router that receives the packet sends the copies to all its
neighbors. Finally, each and every router receives a copy of the same
information. A router sends the information to every other router only when the
change occurs in the information.
Program:-
#include <stdio.h>
#include
<string.h> int
main()
{
int count,src_router,i,j,k,w,v,min;
int cost_matrix[100][100],dist[100],last[100];
int flag[100];
printf("\n Enter the no of routers");
scanf("%d",&count);
printf("\n Enter the cost matrix values:");
for(i=0;i<count;i++)
{
for(j=0;j<count;j++)
{
printf("\n%d->%d:",i,j);
scanf("%d",&cost_matrix[i][j]);
if(cost_matrix[i][j]<0)cost_matrix[i][j]=1000;
}
}
printf("\n Enter the source router:");
scanf("%d",&src_router);
for(v=0;v<count;v++)
{
flag[v]=0;
last[v]=src_router;
dist[v]=cost_matrix[src_router][v];
}
flag[src_router]=1;
for(i=0;i<count;i++
)
{
min=1000;
for(w=0;w<count;w++
)
{
if(!flag[w])
if(dist[w]<min
)
{
v=w;
min=dist[w]
;
}
}
flag[v]=1;
for(w=0;w<count;w++
)
{
if(!flag[w])
if(min+cost_matrix[v][w]<dist[w])
{
dist[w]=min+cost_matrix[v][w];
last[w]=v;
}
}
}
for(i=0;i<count;i++)
{
printf("\n%d==>%d:Path
taken:%d",src_router,i,i); w=i;
while(w!=src_router)
{
printf("\n<--%d",last[w]);w=last[w];
}
printf("\n Shortest path cost:%d",dist[i]);
}
}
Output:-
Enter the no of routers3
Enter the cost matrix values:
0->0:
[exam47@cselinux ~]$ ./a.out
Enter the no of routers2 Enter
the cost matrix values:
0->0:3
0->1:4
1->0:5
1->1:6
Enter the source router:1
1==>0:Path taken:0
<--1
Shortest path cost:5
1==>1:Path taken:1
Shortest path cost:6
Result:-
Thus the implementation of link state routing algorithm was
implemented and successfully verified.
Data Encryption & Decryption Using Data Encryption
Standard Algorithm
AIM:-
To implement the data encryption and decryption using DES.
Software Required:-
Turbo C-Programming.
Algorithm:-
STEP-1 - Start.
STEP-2 - The process begins with the 64-bit plain text block getting
handed over to an initial permutation (IP) function.
STEP-3 - The initial permutation (IP) is then performed on the plain text.
STEP-4 - Next, the initial permutation (IP) creates two halves of the
permuted block, referred to as Left Plain Text (LPT) and Right Plain Text (RPT).
STEP-6 - Finally, the LPT and RPT are rejoined, and a Final
Permutation (FP) is performed on the newly combined block.
STEP-7 -The result of this process produces the desired 64-bit ciphertext.
STEP-8 - Stop.
Procedure:-
DES stands for Data Encryption Standard. There are certain machines that
can be used to crack the DES algorithm. The DES algorithm uses a key of 56-bit
size. Using this key, the DES takes a block of 64-bit plain text as input and
generates a block of 64-bit cipher text.The DES process has several steps
involved in it, where each step is called a round. Depending upon the size of the
key being used, the number of rounds varies. For example, a 128-bit key requires
10 rounds, a 192-bit key requires 12 rounds, and so on.
Program:-
#include <stdio.h>
required0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0,
0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1,
1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0,
1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1
};
int Permutated_Choice1[56] =
};
int Permutated_Choice2[48] =
};
};
int Final_Permutation[] =
};int P[] =
2, 8, 24, 14,
32, 27, 3, 9,
22, 11, 4, 25
};
int E[] =
32, 1, 2, 3, 4, 5,
4, 5, 6, 7, 8, 9,
};
int S1[4][16] =
};
int S3[4][16] =
};
int S4[4][16] =
};
int S5[4][16] =
};
int S6[4][16] =
};
int S8[4][16]=
};
int shifts_for_each_round[16] = { 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
}; int _56bit_key[56];
int _48bit_key[17][48];
int EXPtext[48];
int
XORtext[48];
int X[8][6];
int
X2[32]; int
R[32];
int chiper_text[64];
int encrypted_text[64];
return (a ^ b);
void Dec_to_Binary(int n)
int binaryNum[1000];
int i = 0;
while (n > 0) {
binaryNum[i] = n %
2;n = n / 2;
i++;
text_to_bits[bits_size++] = binaryNum[j];
}
int F1(int i)
int r, c, b[6];
r = b[0] * 2 + b[5];
if (i == 0)
return S1[r][c];
else if (i == 1)
return S2[r][c];
else if (i == 2)
return S3[r][c];
else if (i == 3)
return S4[r][c];
else if (i == 4)
return S5[r][c];
else if (i == 5)
return S6[r][c];
else if (i == 6)
return S7[r][c];
else if (i == 7)
return S8[r][c];
int i;
+ 1) break;
R[i] = bit;
int k, j, m;
static int i;
if (i % 32 == 0)
i = 0;
for (j = 3; j >= 0; j--)
m = 1 << j;
k = value &
m; if (k == 0)
else
i = i + 4;
int k = 0;
6; j++) X[i][j] =
XORtext[k++]; int
value;
{
value = F1(i);
ToBits(value)
EXPtext[i] = bit;
expansion_function(i, Right32[Round -
if (mode == 0)
XORtext[i] = XOR(EXPtext[i],
_48bit_key[Round][i]); else
SBox(XORtext);
i++)PBox(i, X2[i]);
int i;
if (Final_Permutation[i] == pos +
1) break;
encrypted_text[i] = bit;
64; i++) {
IP_result [i] = plain_bits[ Iintial_Permutation[i] ];
Left32[0][i] =
Right32[0][i - 32] =
17; k++)
cipher(k, 0);
Left32[k][i] = Right32[k - 1][i]; // right part comes as it is to next round left part
if (i < 32)
chiper_text[i] =
Right32[16][i]; else
finalPermutation(i, chiper_text[i]);
}
for (int i = 0; i < 64; i++)
printf("%d", encrypted_text[i]);
for(int i=0;plain_text[i];i++){
int asci =
plain_text[i];
Dec_to_Binary(asci);
int i;
if (Permutated_Choice2[i] == pos +
1) break;
_48bit_key[round][i] = bit;
int i;
for (i = 0; i < 56; i++)
if (Permutated_Choice1[i] == pos +
1) break;
_56bit_key[i] = bit;
int k, backup[17][2];
int CD[17][56];
i++) key64to56(i,
C[0][i] =
_56bit_key[i]; else
D[0][i - 28] =
shift];
k = 0;
1][k++];
shift];
k = 0;
1][k++];
CD[j][i]);
int main(){
convert_Text_to_bits(plain_text);
return 0;
}
Output:-
Decrypted output is
0000111001101001001100011010111010010110111010111111111000010111
0010111110111111010100110111010110110000001110111001000000101101
0100010101100001100100000010100000101001111010100101100011101001
1001110010110011011110110001101110000000001000001001000110111010
Result:-
Thus the implementation of DES algorithm was verified.
Data Encryption & Decryption Using RSA Algorithm
AIM:-
To implement the encryption and decryption using the RSA algorithm.
Software Required:-
Turbo C-Programming.
Algorithm:-
STEP-1 - Start.
STEP-6 - Stop.
Procedure:-
The Public key is used for encryption, and the Private Key is used for
decryption. Decryption cannot be done using a public key. The two keys are
linked, but the private key cannot be derived from the public key. The public key
is well known, but the private key is secret and it is known only to the user who
owns the key. It means that everybody can send a message to the user using
user's public key. But only the user can decrypt the message using his private
key.
Program:-
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h
>
int x, y, n, t, i, flag;
long int e[50], d[50], temp[50], j, m[50], en[50];
char msg[100];
int prime(long int);
void
encryption_key(); long
int cd(long int); void
encrypt();
void decrypt();
int main()
{
printf("\nENTER FIRST PRIME NUMBER\n");
scanf("%d",
&x); flag =
prime(x); if(flag
== 0)
{
printf("\nINVALID
INPUT\n"); exit(0);
}
printf("\nENTER SECOND PRIME NUMBER\n");
scanf("%d", &y);
flag = prime(y);
if(flag == 0 || x ==
y)
{
printf("\nINVALID
INPUT\n"); exit(0);
}
printf("\nENTER MESSAGE OR STRING TO ENCRYPT\n");
scanf("%s",msg);
for(i = 0; msg[i] != NULL;
i++) m[i] = msg[i];
n = x * y;
t = (x-1) * (y-1);
encryption_key();
printf("\nPOSSIBLE VALUES OF e AND d
ARE\n"); for(i = 0; i < j-1; i++)
printf("\n%ld\t%ld", e[i],
d[i]); encrypt();
decrypt();
return 0;
}
int prime(long int pr)
{
int i;
j = sqrt(pr);
for(i = 2; i <= j; i++)
{
if(pr % i ==
0) return 0;
}
return 1;
}
Result:-
Thus the encryption and decryption of the data using the RSA algorithm was
implemented and verified sucessfully.
Implement Client Server Model Using Ftp Protocol
AIM:-
To implement the client server model using the FTP protocol.
Software Required:-
Turbo C-Programming.
Algorithm:-
STEP-1 - Start.
STEP 6: Listen and accept the client’s request for the connection.
Output:-
Result:-
Thus the program for FTP client server was executed and the output was
verified.
Performance Analysis Of Csma/Ca And Csma/Cd Protocols
Aim:-
To create scenario and study the performance of CSMA / CD protocol through
simulation.
Software required:-
Ns-2.
Algorithm:-
STEP-1 - Start.
STEP-3 - Open a nam trace file and define finish procedure then close the
trace file, and execute nam on trace file.
STEP-4 - Create duplex links between the nodes and add Orientation to the
nodes for setting a LAN topology.Setup TCP Connection between n(0) and n(4).
Program:-
CSMA/CA
set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
#Open the Trace files
set file1 [open out.tr
w]
set winfile [open WinFile w]
$ns trace-all $file1
#Open the NAM trace
file set file2 [open
out.nam w]
$ns namtrace-all $file2
#Define a 'finish' procedure
proc finish {} {
global ns file1 file2
$ns flush-trace
close $file1
close $file2
exec nam out.nam &
exit 0
}
#Create six nodes set n0
[$ns node] set n1 [$ns
node] set n2 [$ns node]
set n3 [$ns node] set n4
[$ns node] set n5 [$ns
node]
$n1 color red
$n1 shape box
#Create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns simplex-link $n2 $n3 0.3Mb 100ms DropTail
$ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
set lan [$ns newLan "$n3 $n4 $n5" 0.5Mb 40ms LL Queue/DropTail
MAC/Csma/Ca Channel]
Setup a TCP connection
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n4 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
$tcp set window_ 8000
$tcp set packetSize_ 552
#Setup a FTP over TCP connection set ftp
[new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
#Setup a UDP connection set udp
[new Agent/UDP]
$ns attach-agent $n1 $udp set null
[new Agent/Null]
$ns attach-agent $n5 $null
$ns connect $udp $null
$udp set fid_ 2
#Setup a CBR over UDP connection set
cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 0.01mb
$cbr set random_ false
$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 124.0 "$ftp stop"
$ns at 124.5 "$cbr stop"
# next procedure gets two arguments: the name of the #
tcp source node, will be called here "tcp",
# and the name of output file.
proc plotWindow {tcpSource file} { global
nsset time 0.1
set now [$ns now]
set cwnd [$tcpSource set cwnd_] set wnd
[$tcpSource set window_] puts $file "$now
$cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file" }
$ns at 0.1 "plotWindow $tcp $winfile"
$ns at 5 "$ns trace-annotate \"packet drop\""#
PPP
$ns at 125.0 "finish"
$ns run
Output:-
CSMA/CD
set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
#Open the Trace files set
file1 [open out.tr w]
set winfile [open WinFile w]
$ns trace-all $file1
#Open the NAM trace file set
file2 [open out.nam w]
$ns namtrace-all $file2
#Define a 'finish' procedure proc
finish {} {
global ns file1 file2
$ns flush-trace close
$file1 close $file2
exec nam out.nam & exit 0
}
#Create six nodes set
n0 [$ns node] set n1
[$ns node] set n2 [$ns
node] set n3 [$ns node]
set n4 [$ns node] set n5
[$ns node]
$n1 color red
$n1 shape box
#Create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns simplex-link $n2 $n3 0.3Mb 100ms DropTail
$ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
set lan [$ns newLan "$n3 $n4 $n5" 0.5Mb 40ms LL Queue/DropTail
MAC/Csma/Cd Channel]
Setup a TCP connection
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n4 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
$tcp set window_ 8000
$tcp set packetSize_ 552
#Setup a FTP over TCP connection set ftp
[new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
#Setup a UDP connection set udp
[new Agent/UDP]
$ns attach-agent $n1 $udp set null
[new Agent/Null]
$ns attach-agent $n5 $null
$ns connect $udp $null
$udp set fid_ 2
#Setup a CBR over UDP connection set
cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 0.01mb
$cbr set random_ false
$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 124.0 "$ftp stop"
$ns at 124.5 "$cbr stop"
# next procedure gets two arguments: the name of the #
tcp source node, will be called here "tcp",
# and the name of output file.
proc plotWindow {tcpSource file} { global
nsset time 0.1
set now [$ns now]
set cwnd [$tcpSource set cwnd_] set wnd
[$tcpSource set window_] puts $file "$now
$cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file" }
$ns at 0.1 "plotWindow $tcp $winfile"
$ns at 5 "$ns trace-annotate \"packet drop\""
# PPP
$ns at 125.0 "finish"
$ns run
Output:-
Result:-
Thus, the performance of CSMA / CD protocol was studied through
simulation.
Implementation of Star & Ring Topology
AIM:
To create scenario and study the performance of token ring protocols through
simulation.
SOFTWARE REQUIREMENTS:
NS-2
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.
Procedure:
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: Whenthere 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 e 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.
The star topology reduces the damage caused by line failure by connecting
all of the systems to a central node. All peripheral nodes may thus communicate
with all others by transmitting to, and receiving from, the central node only. The
failure of a transmission line linking any peripheral node to the central node will
result in the isolation of that peripheral node from all others, but the rest of the
systems will be unaffected.
Program:-
Star topology:-
#Create a simulator
object set ns [new
Simulator]
#Open the nam trace
file set nf [open
out.nam w]
$ns namtrace-all $nf
#Define a 'finish'
procedure proc finish {}
{
global ns nf
$nsflush-trace
#Close the trace file
close $nf
#Executenam on the trace
file exec nam out.nam &
exit0
}
#Create six nodes set n0
[$ns node] set n1 [$ns
node] set n2 [$ns node] set
n3 [$ns node] set n4 [$ns
node] set n5 [$ns node]
#Change the shape of center node in a star topology
$n0 shape square
#Create links between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n0 $n2 1Mb 10ms DropTail
$ns duplex-link $n0 $n3 1Mb 10ms DropTail
$ns duplex-link $n0 $n4 1Mb 10ms DropTail
$ns duplex-link $n0 $n5 1Mb 10ms DropTail
#Create a TCP agent and attach it to node n0 set tcp0
[new Agent/TCP]
$tcp0 set class_ 1
$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 attach-agent $n3 $sink0
#Connect the traffic sources with the traffic sink
$ns connect $tcp0 $sink0
# Create a CBR traffic source and attach it to tcp0 set cbr0
[new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.01
$cbr0 attach-agent $tcp0
#Schedule events for the CBR agents
$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run
Output:-
Ring topology:-
#Create a simulator
object set ns [new
Simulator]
#Open the nam trace
file set nf [open
out.nam w]
$ns namtrace-all $nf
#Define a 'finish'
procedure proc finish {}
{
global ns nf
$nsflush-trace
#Close the trace
file close $nf
#Executenam on the trace
file exec nam out.nam &
exit0
}
#Create five
nodes set n0
[$ns node] set
n1 [$ns node]
set n2 [$ns
node] set n3
[$ns node] set
n4 [$ns node]
set n5 [$ns
node]
#Create links between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 1Mb 10ms DropTail
$ns duplex-link $n3 $n4 1Mb 10ms DropTail
$ns duplex-link $n4 $n5 1Mb 10ms DropTail
$ns duplex-link $n5 $n0 1Mb 10ms DropTail
#Create a TCP agent and attach it to node n0 set
tcp0 [new Agent/TCP]
$tcp0 set class_ 1
$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 attach-agent $n3 $sink0
#Connect the traffic sources with the traffic sink
$ns connect $tcp0 $sink0
# Create a CBR traffic source and attach it to tcp0 set
cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.01
$cbr0 attach-agent $tcp0
#Schedule events for the CBR agents
$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run
Output:-
Result:-
Thus the and Star and Ring Topology was simulated and studied.