Professional Documents
Culture Documents
GNANAMANI COLLEGE
NAMAKKAL OF TECHNOLOGY,
– 637018
NAMAKKAL - 637 018
INSTITUTE
VISION
Emerging as a technical institution of high standard and excellence to produce quality Engineers,
Researchers, Administrators and Entrepreneurs with ethical and moral key values to contribute the
sustainable development of the society.
MISSION
MI1: To have in-depth domain knowledge with analytical and practical skills in cutting edge technologies
by imparting quality technical education.
MI2: To be industry ready and multi-skilled personalities to transfer technology to industriesand rural areas
by creating interests among students in Research and Development and Entrepreneurship.
DEPARTMENT
VISION
MISSION
• Imparting quality education through latest technologies to prepare Students as software developer
and system analyst.
PEO-2: Demonstrate ethical keys, effective communication and team skills in their profession and
adapt to current trends through lifelong learning.
1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and
an engineering specialization to the solutionof complex engineering problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and
engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the public
health and safety, and the cultural, societal, and environmental considerations
4. Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to
provide keyid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering
and IT tools including prediction and modeling to complex engineering activities with an understanding of
the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal,
health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice.
7. Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the
engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader in diverse
teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports and
design documentation, make effective presentations, and give and receive clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the engineering and
management principles and apply these to one’s own work, as a member and leader in a team, to manage
projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technologicalchange.
CS3591 COMPUTER NETWORKS LAB LT PC
3 0 2 4
COURSE OBJECTIVES:
At the end of this course, the students will be able to:
CO1: To learn and use network commands.
CO2: To learn socket programming.
CO3: To implement and analyze various network protocols.
CO4: To learn and use simulation tools.
CO5:To use simulation tools to analyze the performance of various network protocols.
1. Learn to use commands like tcpdump, netstat, ipconfig, nslookup and traceroute.
Capture ping and trace route PDUs using a network protocol analyzer and examine.
2. Write a HTTP web client program to download a web page using TCP sockets.
3. Applications using TCP sockets like: a) Echo client and echo server b) Chat
4. Simulation of DNS using UDP sockets.
5. Use a tool like Wireshark to capture packets and examine the packets
6. Write a code simulating ARP /RARP protocols.
7. Study of Network simulator (NS) and Simulation of Congestion Control Algorithms using NS.
8. Study of TCP/UDP performance using Simulation tool.
9. Simulation of Distance Vector/ Link State Routing algorithm.
10. Simulation of an error correction code (like CRC)
COURSE OUTCOMES:
At the end of this course, the students will be able to:
• Implement various protocols using TCP and UDP.
• Compare the performance of different transport layer protocols.
• Use simulation tools to analyze the performance of various network protocols.
• Analyze various routing algorithms.
• Implement error correction codes.
GNANAMANI COLLEGE OF TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
NAME OF THE LAB : COMPUTER NETWORKS
SUBJECT CODE : CS3591 YEAR/BRANCH/SEM : III-B.E-CSE/V
COURSE OUTCOMES
LIST OF EXPERIMENTS
S. BLOOMS
NAME OF EXPERIMENTS COs
NO LEVEL
Learn to use commands like tcpdump, netstat, ifconfig, nslookup and
1 traceroute. Capture ping and trace route PDUs using a network protocol L3 CO3
analyzer and examine.
Write a HTTP web client program to download a web page using TCP
2 L3 CO1
sockets.
3 Applications using TCP sockets like: a) Echo client & Echo server b) Chat L3 CO1
5 Use a tool like Wireshark to capture packets and examine the packets L4 CO2
*BL: (L1- Remembering, L2- Understanding, L3- Applying, L4- Analysing, L5- Evaluating, L6-Creating)
Ex. No: 1.(a) LEARN TO USE COMMANDS LIKE NSLOOKUP, NETSTAT, IPCONFIG,
Date: TRACEROUTE AND TCPDUMP
AIM
To Learn to use commands like nslookup, tcpdump, netstat, ifconfig and traceroute.
Tracert command
“tracert” in Windows stands for “Trace Route”. In Linux, the same command is
“traceroute”. The command traces the path that a TCP/IP packet takes towards a destination target
and shows some information (if available) of the routing nodes within this path.
Just like the “ping” command, “tracert” sends also ICMP echo packets to the destination with
varying Time-to-Live (TTL) values.
tracert [domain or IP] : Traces TCP/IP path to specified destination target IP or domain.
Example:
tracert [domain]
C:/> tracert www.google.com
Example:
tracert [IP Address]
C:/> tracert 172.16.26.163
Example:
tracert [IP address]
C:/> tracert 8.8.8.8
Nslookup command
“nslookup” stands for “Name System Lookup” and is very useful in obtaining Domain
Name System (DNS) related information about a domain or about an IP address.
nslookup [domain name]: This command is to find quickly the IP address of a specific domain
name (A-record) as shown below:
Example: nslookup [Domain name]
C:/> nslookup www.google.com
As shown above, the “nslookup” command followed by a domain name will show you the IPv4 and
IPv6 addresses (A records and AAAA records) assigned to the specific domain.
nslookup [IP Address]: This will perform a reverse-DNS lookup and will try to match the given IP
address in the command with its corresponding domain name.
Example: nslookup [IP address]
C:/> nslookup 8.8.8.8
Ping command
Command that every computer user runs on the command line when having connectivity problems
is the “ping” command. This will quickly show you if can send and receive packets (icmp packets to be
exact) from your computer and hence shows whether you have network connectivity or not. Ping is useful
for testing connectivity for both the local computer from where you execute the command and also for a
remote computer or server which try to reach.
ping [IP Address] : By default it will send 4 ICMP packets to the stated IP address.
ping [IP address] -t : This will send ping packets (icmp echo requests) continuously to the target IP.
ping -n 10 [IP address] : This will send 10 ping packets (icmp echo requests) to the target IP.
Netstat Command:
The netstat command generates displays that show network status and protocol statistics.
The network statistics ( netstat ) command is a networking tool used for troubleshooting and
configuration, that can also serve as a monitoring tool for connections over the network. Both
incoming and outgoing connections, routing tables, port listening, and usage statistics are common uses for
this command.
netstat -a: netstat –a Displays all active ports
netstat -e: netstat –e Shows statistics about your network connection (received and sent data packets)
RESULT
Thus the Learning to use commands like nslookup, tcpdump, netstat, ifconfig and traceroute was
performed.
Ex. No: 1.(b)
CAPTURE PING PDUS USING A NETWORK PROTOCAL ANALYZER
Date:
AIM
PROGRAM
import java.util.*;
public class Ping {
public void ping(String host) {
try
{
Process p = Runtime.getRuntime().exec("ping"+host);
Scanner scan = new Scanner(p.getInputStream());
while(scan.hasNextLine())
{
System.out.println(scan.nextLine());
}}
catch(Exception ex){
System.out.println("Error "+ex);
}}
public static void main(String args[])
{
Ping p=new Ping();
p.ping(args[0]);
}}
OUTPUT
RESULT
Thus the java program to simulate ping command was executed successfully.
EX. NO:1(c)
Date: SIMULATION OF TRACEROUTE COMMAND
AIM
ALGORITHM
PROGRAM
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class traceroutecmd
{
public static void runSystemCommand(String command)
{
try
{
Process p = Runtime.getRuntime().exec(command);
BufferedReader inputStream = new BufferedReader(new InputStreamReader(p.getInputStream()));
String s ="";
while((s = inputStream.readLine())!= null)
System.out.println(s);
}
catch (Exception e)
{ }
}
public static void main(String[] args)
{
String ip = "www.google.com";
runSystemCommand("tracert " + ip);
}
}
OUTPUT
RESULT
Thus the java program to simulate trace route command was executed successfully.
EX. NO:2
Date: DOWNLOADING A WEB PAGE
AIM
To Write a HTTP web client program to download a web page using Java Programming.
ALGORITHM
PROGRAM
import java.io.*;
import java.net.URL;
import java.net.MalformedURLException;
public class download {
public static void downloadpage(String webpage)
{
try {
URL url = new URL(webpage);
BufferedReader readr = new BufferedReader(new InputStreamReader(url.openStream()));
BufferedWriter writer = new BufferedWriter(new FileWriter("gk.html"));
String line;
while((line = readr.readLine()) != null) {
writer.write(line); }
readr.close();
writer.close();
System.out.println("Successfully Downloaded."); }
catch (MalformedURLException mue) {
System.out.println("Malformed URL Exception raised");
}
catch (IOException ie)
{
System.out.println("IOException raised");
} }
public static void main(String args[]) throws IOException
{ String url = "https://www.google.com";
downloadpage(url);
} }
OUTPUT
RESULT
Thus, the HTTP web client program to download a web page was executed successfully.
EX. NO:3a APPLICATIONS USING TCP SOCKETS LIKE:
Date: ECHO CLIENT & SERVER
AIM
To create the TCP socket for Echo Client and Server Application using java programming.
ALGORITHM
CLIENT SIDE
1. Create a socket which binds the IP address of server and the port address.
2. After establishing connection send a data to server.
3. Receive and print the same data from server.
4. Close the Socket & End the program.
SERVER SIDE
SERVER PROGRAM:
import java.io.*;
import java.net.*;
class echoserver
{
public static void main(String args[]) throws Exception
{
ServerSocket ss =new ServerSocket(111);
Socket s=ss.accept();
DataInputStream in= new DataInputStream(s.getInputStream());
DataOutputStream out=new DataOutputStream(s.getOutputStream());
String str;
System.out.println("\nSERVER SIDE!...");
while(true)
{
str=in.readLine();
out.writeBytes(str);
System.out.println("\nMsg from Client");
System.out.println(str+"\n");
}
}
}
CLIENT PROGRAM
import java.io.*;
import java.net.*;
class echoclient
{
public static void main(String args[]) throws Exception
{
DataInputStream in=new DataInputStream(System.in);
Socket s=new Socket("LocalHost",111);
DataInputStream inecho=new DataInputStream(s.getInputStream());
DataOutputStream out=new DataOutputStream(s.getOutputStream());
String str,str1;
System.out.println("\nCLIENT SIDE! \nEnter Client Msg");
while((str=in.readLine())!=null)
{
out.writeBytes(str+"\n");
}
}
}
SERVER OUTPUT
CLIENT OUTPUT
RESULT
Thus the TCP socket for Echo client and Echo Server Application using java programming was
performed.
EX. NO: 3b CHAT APPLICATION USING TCP SOCKETS
Date:
AIM
To create the TCP sockets for Chat Application using java programming.
ALGORITHM
1. Create Data InputStream and Data OutputStream objects for Data flow
2. Create a socket and include port number and local host IP address in client program.
3. Create a server socket and include port number.
4. Declare accept() in the server program and accept() are accessed by using server socket object.
5. Declare writeBytes() to write the messages sent between the client and server.
6. Declare readLine() to read the contents of client and server.
SERVER PROGRAM
import java.io.*;
import java.net.*;
class schat
Socket s=ss.accept();
while(s!=null)
String m2;
System.out.println("Server:");
while(true)
String m1=in1.readLine();
m2=in.readLine();
out.writeBytes(m2+"\n");
in1.close();
out.close();
s.close();
ss.close();
CLIENT PROGRAM
import java.io.*;
import java.net.*;
public class cchat
{
public static void main(String args[]) throws Exception
{
Socket s=new Socket("LocalHost",123);
DataInputStream in1=new DataInputStream(System.in);
DataInputStream in2=new DataInputStream(s.getInputStream());
DataOutputStream out=new DataOutputStream(s.getOutputStream());
if(s!=null)
{
String inp;
System.out.println("Enter the message:");
while((inp=in1.readLine())!=null)
{
if(inp.equals("exit"))
break;
out.writeBytes(inp+"\n");
System.out.println("Echo message from server:"+in2.readLine());
System.out.println("Enter ur message:");
}
}
}
}
SERVER OUTPUT
CLIENT OUTPUT
RESULT
Thus the TCP sockets for Chat Application using java programming was performed.
EX. NO: 4.a SIMULATING ARP PROTOCOL
Date:
AIM
To Simulate ARP protocol for client and server application using Java programming.
ALGORITHM
CLIENT SIDE
SERVER SIDE
1. Accept the connection request by the client.
2. Get the IP address from its inputstream.
3. During runtime execute the process using Process p=r.exec("arp -a "+ip);
4. Send the Physical Address to the client.
SERVER PROGRAM:
import java.io.*;
import java.net.*;
class arps
{
public static void main(String args[]) throws IOException
{
try
{
ServerSocket ss=new ServerSocket(111);
Socket s=ss.accept();
PrintStream ps=new PrintStream(s.getOutputStream());
BufferedReader br1=new BufferedReader(new InputStreamReader(s.getInputStream()));
String ip;
ip=br1.readLine();
Runtime r=Runtime.getRuntime();
Process p=r.exec("arp -a "+ip);
BufferedReader br2=new BufferedReader(new InputStreamReader(p.getInputStream()));
String str;
while((str=br2.readLine())!=null)
{
ps.println(str);
}}
catch(IOException e)
{
System.out.println("Error"+e);
}}}
CLIENT PROGRAM
import java.io.*;
import java.net.*;
class arpc
{
public static void main(String args[]) throws IOException
{
try
{
Socket ss=new Socket(InetAddress.getLocalHost(),111);
PrintStream ps=new PrintStream(ss.getOutputStream());
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String ip;
System.out.println("Enter the IP ADDRESS:");
ip=br.readLine();
ps.println(ip);
String str,data;
BufferedReader br2=new BufferedReader(new InputStreamReader(ss.getInputStream()));
System.out.println("ARP From Server:");
do
{
str=br2.readLine();
System.out.println(str);
}
while(!(str.equalsIgnoreCase("end")));
}
catch(IOException e)
{
System.out.println("Error"+e);
}}}
SERVER SIDE
RESULT
Thus the Simulation of ARP protocol for client and server application using Java
programming was performed.
EX. NO: 4.b SIMULATING ARP /RARP PROTOCOLS
Date:
AIM
To write a java program for simulating RARP protocols.
ALGORITHM
CLIENT SIDE
1. Start the program
2. using datagram sockets UDP function is established.
3. Get the MAC address to be converted into IP address.
4. Send this MAC address to server.
5. Server returns the IP address to client.
SERVER SIDE
1. Start the program.
2. Server maintains the table in which IP and corresponding MAC addresses are stored.
3. Read the MAC address which is send by the client.
4. Map the IP address with its MAC address and return the IP address to client.
SERVER PROGRAM
import java.io.*;
import java.net.*;
import java.util.*;
public class rarps
{
public static void main(String args[])
{
try
{
DatagramSocket server=new DatagramSocket(1309);
while(true)
{
byte[] sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];
DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);
server.receive(receiver);
String str=new String(receiver.getData());
String s=str.trim();
InetAddress addr=receiver.getAddress();
int port=receiver.getPort();
String ip[]={"165.165.80.80","165.165.79.1"};
String mac[]={"6A:08:AA:C2","8A:BC:E3:FA"};
for(int i=0;i<ip.length;i++)
{
if(s.equals(mac[i]))
{
sendbyte=ip[i].getBytes();
DatagramPacket sender=new DatagramPacket(sendbyte,sendbyte.length,addr,port);
server.send(sender);
break;
} }
break;
} }
catch(Exception e)
{
System.out.println(e);
}}}
CLIENT PROGRAM
import java.io.*;
import java.net.*;
import java.util.*;
public class rarpc
{
public static void main(String args[])
{
try
{
DatagramSocket client=new DatagramSocket();
InetAddress addr=InetAddress.getByName("127.0.0.1");
byte[] sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Physical address (MAC):");
String str=in.readLine();
sendbyte=str.getBytes();
DatagramPacket sender=new DatagramPacket(sendbyte,sendbyte.length,addr,1309);
client.send(sender);
DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);
client.receive(receiver);
String s=new String(receiver.getData());
System.out.println("The Logical Address is (IP): "+s.trim());
client.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
OUTPUT
RESULT
Thus the Simulation of RARP protocol using Java programming was performed.
EX. NO: 5 SIMULATION OF DNS USING UDP SOCKETS
Date:
AIM
To Simulate the concept of DNS using UDP Sockets using Java programming.
ALGORITHM
SERVER PROGRAM
dnsserver .java:
import java.io.*;
import java.net.*;
public class dnsserver
{
private static int indexOf(String[] array, String str)
{
str = str.trim();
for (int i=0; i < array.length; i++)
{
if (array[i].equals(str))
return i;
}
return -1;
}
public static void main(String arg[])throws IOException
{
String[] hosts = {"yahoo.com", "gmail.com","cricinfo.com", "facebook.com"};
String[] ip = {"68.180.206.184", "209.85.148.19","80.168.92.140", "69.63.189.16"};
while(true)
{
DatagramSocket serversocket=new DatagramSocket(1362);
byte[] senddata = new byte[1021];
byte[] receivedata = new byte[1021];
DatagramPacket recvpack = new DatagramPacket(receivedata, receivedata.length);
serversocket.receive(recvpack);
String sen = new String(recvpack.getData());
InetAddress ipaddress = recvpack.getAddress();
int port = recvpack.getPort();
String capsent;
System.out.println("Request for host " + sen);
if(indexOf (hosts, sen) != -1)
capsent = ip[indexOf (hosts, sen)];
else
capsent = "Host Not Found";
senddata = capsent.getBytes();
DatagramPacket pack = new DatagramPacket (senddata, senddata.length,ipaddress,port);
serversocket.send(pack);
serversocket.close();
}
}
}
CLIENT PROGRAM
dnsclient.java:
import java.io.*;
import java.net.*;
public class dnsclient
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
DatagramSocket clientsocket = new DatagramSocket();
InetAddress ipaddress;
if (args.length == 0)
ipaddress = InetAddress.getLocalHost();
else
ipaddress = InetAddress.getByName(args[0]);
byte[] senddata = new byte[1024];
byte[] receivedata = new byte[1024];
int portaddr = 1362;
System.out.print("Enter the hostname: ");
String sentence = br.readLine();
senddata = sentence.getBytes();
DatagramPacket pack = new DatagramPacket(senddata,senddata.length, ipaddress,portaddr);
clientsocket.send(pack);
DatagramPacket recvpack =new DatagramPacket(receivedata,receivedata.length);
clientsocket.receive(recvpack);
String modified = new String(recvpack.getData()); System.out.println("IP Address: " + modified);
clientsocket.close();
}
}
OUTPUT
SERVER SIDE
CLIENT SIDE
RESULT
Thus the Simulation of DNS using UDP Sockets using Java programming was performed.
EX. NO: 6 WIRESHARK TOOL TO CAPTURE AND EXAMINE PACKETS
Date:
AIM
To use a tool like wireshark to capture packets and examine the packets.
ALGORITHM
1. Open Wireshark.
2. Set a capture filter, and select the interface on which to capture.
3. Start the capture.
4. Generate traffic by connecting to a website.
5. Pinging a remote device or attempting any other network connection.
6. Stop the capture and Examine the Packets.
PROCEDURE
2. Select the interface on which packets need to be captured. This will usually be the interface where
the Packet/s column is constantly changing, which would indicate the presence of live traffic. If
multiple network interface cards (i.e. LAN card and Wi-Fi adapter) are there, Determine the right
interface.
4. Recreate the problem. The capture dialog should show the number of packets increasing. Try to
avoid running any other internet applications while capturing, closing other browsers, Instant
messengers etc.
5. Once the problem which is to be analyzed has been reproduced, click on Stop. It may take a few
seconds for Wireshark to display the packets captured.
6. Save the packet trace in the default format. Click on the File menu option and select Save As. By
default Wireshark will save the packet trace in libpcap format. This is a filename with a.pcap
extension.
OUTPUT
RESULT
Thus the given procedure for wireshark tool to capture packets and examine the packets was
performed successfully.
EX. NO: 7 STUDY OF NETWORK SIMULATOR (NS)
Date:
AIM
To perform the study of Network Simulator (NS) like Cisco Packet Tracer.
DESCRIPTION
Cisco systems are used to design the Cisco packet tracer. It is a dominant network simulation
tool. These are used for designing network topologies and also allowed to imitate these designed
networks in modern computer networks. It is the most commonly used network simulation network.
Cisco Packet Tracer is a vital tool for Network learners as it helps them to prepare for the networking
exams such as CCNA (Cisco Certified Network Associate)
Cisco Packet Tracer is a powerful network simulation and visualization tool by Cisco to practice
networking, IoT, and cybersecurity skills. The virtual learning environment comes in handy to learn
courses, professional training, work planning, and so on.
This software is built by Cisco and can be used to practice Networking related labs virtually.
Packet tracer is an excellent tool for having hands-on experience on devices like Cisco Routers,
Switches, HUB, and end devices like PC, Laptop, Server, and many more.
Click on Cisco Networking Academy and log in to account to get started with the Cisco packet tracer.
Step 2 - Click on PC and drag it to place it in the workspace. Place two PCs like this.
Now, these two PCs are connected, and in order to check the connectivity, follow the steps below:
Check the action status in the PDU list window on the bottom right side.
Network Simulation:
Finally, Network with 4 hosts, 2 switches and 2 routers are configured like below:
RESULT
Thus the study of Network Simulator (NS) like Cisco Packet Tracer was performed successfully.
EX. NO: 8 SIMULATION OF DISTANCE VECTOR ROUTING
DATE: ALGORITHM
AIM
To simulate the concept of a Distance Vector/Link State Routing using the Cisco Packet Tracer.
PROCEDURE
6. After that set the IP address of all the PCs by clicking on the PC and choose desktop option and
IP config to set the IP address and the default gateway address of the PCs.
7. Now set the IP address of the routers by click on the router and select config and choose Fast
Ethernet option and set the IP and on the Port status.
8. Now choose the Serial2/0 to set the IP address of the neighbor routers and for the second
define the Serial3/0 IP address as given in the Image.
9. Now click on the RIP option and give the neighbors IP address in all the Routers.
10. Now for check the connection we can send the message from one PC to another.
OUTPUT
RESULT
Thus the simulation of the Distance Vector using the Cisco Packet Tracer was performed.
EX. NO: 9 STUDY OF TCP/UDP PERFORMANCE USING
DATE: SIMULATION TOOL
AIM
ALGORITHM
1. Create a simulation object
2. Set routing protocol to routing
3. Trace packets and all links onto NAM trace and to trace file
4. Create right nodes
5. Describe their layout topology
6. Add a sink agent to node
7. Connect source and sink.
8. Observe the traffic route when link is up and down
9. View the simulated events and trace file analyze it
10. Start the scheduler
UDPTCP.TCL
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exit 0 }
set n0 [$ns node]
$ns run
OUTPUT
RESULT
Thus, the performance of TCP/UDP using Network Simulator was studied and output is
verified successfully
EX. NO: 10
SIMULATION OF ERROR DETECTION CODE (LIKE CRC)
DATE:
AIM
To Simulate the concept of Error Detection & Correction code like CRC using Java.
ALGORITHM
1. Open the editor and type the program for error detection
2. Get the input in the form of bits.
3. Append the redundancy bits.
4. Divide the appended data using a divisor polynomial.
5. The resulting data should be transmitted to the receiver.
6. At the receiver the received data is entered.
7. The same process is repeated at the receiver.
8. If the remainder is zero there is no error otherwise there is some error in the received bits
9. Run the program.
PROGRAM
import java.io.*;
class crc
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Generator:");
String gen = br.readLine();
System.out.println("Enter Data:");
String data = br.readLine();
String code = data;
while(code.length() < (data.length() + gen.length() - 1))
code = code + "0";
code = data + div(code,gen);
System.out.println("The transmitted Code Word is: " + code);
System.out.println("Please enter the received Code Word: ");
String rec = br.readLine();
if(Integer.parseInt(div(rec,gen)) == 0)
System.out.println("The received code word contains no errors.");
else
System.out.println("The received code word contains errors.");
}
static String div(String num1,String num2)
{
int pointer = num2.length();
String result = num1.substring(0, pointer);
String remainder = "";
for(int i = 0; i < num2.length(); i++)
{
if(result.charAt(i) == num2.charAt(i))
remainder += "0";
else
remainder += "1";
}
while(pointer < num1.length())
{
if(remainder.charAt(0) == '0')
{
remainder = remainder.substring(1, remainder.length());
remainder = remainder + String.valueOf(num1.charAt(pointer));
pointer++;
}
result = remainder;
remainder = "";
for(int i = 0; i < num2.length(); i++)
{
if(result.charAt(i) == num2.charAt(i))
remainder += "0";
else
remainder += "1";
}
}
return remainder.substring(1,remainder.length());
}
}
OUTPUT
Enter Generator:
1011
Enter Data:
1001010
The transmitted Code Word is: 1001010111
Please enter the received Code Word:
1110110111
The received code word contains errors.
RESULT
Thus the simulation of Error correction Code(CRC) was executed and output is verified
successfully.
CONTENT BEYOND SYLLABUS
Ex. No: 11
DATA ENCRYPTION AND DECRYPTION
Date:
AIM
To implement the simple substitution technique named Caesar cipher using C language.
ALGORITHM
#include <stdio.h>
#include <string.h>
#include<conio.h>
#include <ctype.h>
void main()
{
char plain[10], cipher[10];
int key,i,length;
int result;
clrscr();
printf("\n Enter the plain text:");
scanf("%s", plain);
printf("\n Enter the key value:");
scanf("%d", &key);
printf("\n \n \t PLAIN TEXt: %s",plain);
printf("\n \n \t ENCRYPTED TEXT: ");
for(i = 0, length = strlen(plain); i < length; i++)
{
cipher[i]=plain[i] + key;
if (isupper(plain[i]) && (cipher[i] > 'Z'))
cipher[i] = cipher[i] - 26;
if (islower(plain[i]) && (cipher[i] > 'z'))
cipher[i] = cipher[i] - 26;
printf("%c", cipher[i]);
}
printf("\n \n \t AFTER DECRYPTION : ");
for(i=0;i<length;i++)
{
plain[i]=cipher[i]-key;
if(isupper(cipher[i])&&(plain[i]<'A'))
plain[i]=plain[i]+26;
if(islower(cipher[i])&&(plain[i]<'a'))
plain[i]=plain[i]+26;
printf("%c",plain[i]);
}
getch();
}
OUTPUT
Enter the Plain Text: ZEBRA
Enter the key value: 3
PLAIN TEXT: ZEBRA
ENCRYPTED TEXT: CHEUD
AFTER DECRYPTION: ZEBRA
Enter the Plain Text: zebra
Enter the key value: 3
PLAIN TEXT: zebra
ENCRYPTED TEXT: cheud
AFTER DECRYPTION: zebra
RESULT
Thus the implementation of Caesar cipher has been executed successfully.