[ SENDER SIDE ]
import java.io.*;
import java.net.*;
public class sender
{
public static void main(String args[]) throws Exception
{
int i=0;
int ch;
String input="",output="";
Socket soc=new Socket("localhost",3030);
DataOutputStream dos=new DataOutputStream(soc.getOutputStream());
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Data To Send : ");
input=br.readLine();
for(i=0;i<input.length();i++)
{
ch=(int)input.charAt(i);
ch=ch+3;
if(ch>122 || ch>90 && ch<97)
ch=ch-26;
output=output+(char)ch;
}
System.out.println(output);
dos.writeUTF(output);
}
}
[ RECEIVER SIDE ]
import java.io.*;
import java.net.*;
public class receiver
{
public static void main(String args[]) throws Exception
{
int ch,i;
String input="",output="";
ServerSocket ss=new ServerSocket(3030);
Socket soc=ss.accept();
DataInputStream dis=new DataInputStream(soc.getInputStream());
input=dis.readUTF();
for(i=0;i<input.length();i++)
{
ch=(int)input.charAt(i);
ch=ch-3;
if(ch<65 || ch>90 && ch<97)
ch=ch+26;
output=output+(char)ch;
}
System.out.println("DECRYPTED MESSAGE : "+output);
}
}
No comments:
Post a Comment