Documente Academic
Documente Profesional
Documente Cultură
REG.NO : 18CS506
Name : GAJALAKSHMI
COURSE : MCA / II YEAR
SUBJECT : COMPUTER NETWORKS
OUTPUT
ENCRYPTION AND DECRYPTION
CLIENT
import java.io.*;
import java.util.*;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;
InetAddress ip=InetAddress.getLocalHost();
String a="abcdefghijklmnopqrstuvwxyz";
String b="zyxwvutsrqponmlkjihgfedcba";
String str=br.readLine();
String decrypt=" ";
char c;
for(int i=0;i<str.length();i++)
c=str.charAt(i);
int j=a.indexOf(c);
decrypt=decrypt+b.charAt(j);
byte[] b1=decrypt.getBytes();
ds.send(new DatagramPacket(b1,decrypt.length(),ip,1234));
}
SERVER
import java.io.*;
import java.util.*;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;
ds.receive(p);
String mes1=mes.trim();
String h="zyxwvutsrqponmlkjihgfedcba";
char c;
for(int i=0;i<mes1.length();i++)
c=mes1.charAt(i);
int j=h.indexOf(c);
decrypt=decrypt+a.charAt(j);
}
FINDING PARITY USING CLIENT/SERVER
RECEIVER:
import java.io.*;
import java.net.*;
ServerSocket receiverSocket;
ObjectOutputStream out;
ObjectInputStream in;
receiver(){}
void run()
try{
connection = receiverSocket.accept();
in = new ObjectInputStream(connection.getInputStream());
try{
message = (String)in.readObject();
System.out.println("client>" + message);
parity1=message.substring(0,1);
parity2=String.valueOf(parity(message.substring(1)));
sendMessage(message);
catch(ClassNotFoundException classnot){
//}while(!message.equals("bye"));
catch(IOException ioException){
ioException.printStackTrace();
finally{
try{
in.close();
out.close();
receiverSocket.close();
catch(IOException ioException){
ioException.printStackTrace();
int n=Integer.valueOf(str);
int len=str.length();
int sum=0;
for(int i=0;i<len;i++){
sum+=n%10;
n/=10;
return (sum%2);
try{
out.writeObject(msg);
out.flush();
System.out.println("server>" + msg);
}
catch(IOException ioException){
ioException.printStackTrace();
while(true){
server.run();
}
Sender:
import java.io.*;
import java.net.*;
Socket requestSocket;
ObjectOutputStream out;
ObjectInputStream in;
String message;
boolean check=true;
sender(){}
void run()
try{
out.flush();
in = new ObjectInputStream(requestSocket.getInputStream());
System.out.println("server>" + message);
do{
try{
message = br.readLine();
if(checkbinary(message)){
check=false;
message=String.valueOf(parity(message)).concat(message);
sendMessage(message);
}else{
catch(Exception classNot){
}while(check);
try{
System.out.println("Data sent" );
message = (String)in.readObject();
System.out.println("server>" + message);
}catch(Exception e){}
catch(UnknownHostException unknownHost){
catch(IOException ioException){
ioException.printStackTrace();
catch(Exception e){}
finally{
try{
in.close();
out.close();
requestSocket.close();
catch(IOException ioException){
ioException.printStackTrace();
int n=Integer.valueOf(str);
int len=str.length();
int sum=0;
for(int i=0;i<len;i++){
sum=n%10;
return true;
int n=Integer.valueOf(str);
int len=str.length();
int sum=0;
for(int i=0;i<len;i++){
sum+=n%10;
n/=10;
return (sum%2);
try{
out.writeObject(msg);
out.flush();
System.out.println("client>" + msg);
catch(IOException ioException){
ioException.printStackTrace();
client.run();
}
OUTPUT: