/*
Exercise : Ex 3
Title : Sender Program..
Author :Aslam Jainul
*/
import java.io.*;
import java.net.*;
import java.util.*;
class sender
{
public static void main(String args[])
{
try
{
int key;
DataInputStream dis=new DataInputStream(System.in);
key=2;
System.out.println("enter the name");
String f=dis.readLine();
File f1=new File(f);
FileReader fr=new FileReader(f1);
Socket s=new Socket("192.168.208.118",8081);
PrintWriter put=new PrintWriter(s.getOutputStream(),true);
put.println(f);
int c=0;
while((c=fr.read())!= -1)
{
put.println(c+key);
}
System.out.println("File content transferred");
fr.close();
s.close();
}
catch(Exception e)
{}
}
}
/*
Exercise : Ex 3
Title : Receiver Program..
Author :Aslam Jainul
*/
import java.io.*;
import java.net.*;
import java.util.*;
class receiver
{
public static void main(String args[]) throws IOException
{
ServerSocket ss;
Socket s;
try
{
System.out.println("waiting for client");
ss=new ServerSocket(8081);
s=ss.accept();
System.out.println("connection established");
BufferedReader get=new BufferedReader(new InputStreamReader(s.getInputStream()));
String fname;
fname=get.readLine();
fname="TR_"+fname;
System.out.println("file name is:"+fname);
File f=new File(fname);
FileWriter fw=new FileWriter(f);
String c;
while((c=get.readLine())!=null)
fw.write(Integer.parseInt(c));
System.out.println("received content stored");
fw.close();
s.close();
}
catch(Exception e)
{}
}
}
/*
Exercise : Ex 3
Title : Decrypt File
Author :Aslam Jainul
*/
import java.io.*;
import java.net.*;
import java.util.*;
class decript
{
public static void main(String args[])
{
try
{
DataInputStream dis=new DataInputStream(System.in);
System.out.println("Enter the encrypted file name with extension");
String fname=dis.readLine();
File f1=new File(fname);
FileReader fr=new FileReader(f1);
File f2=new File("dec_"+fname);
FileWriter fw=new FileWriter(f2);
int c=0;
while((c=fr.read())!=-1)
{
System.out.println(c-2);
fw.write(c-2);
}
fr.close();
fw.close();
}
catch(Exception e)
{}
}
}
Exercise : Ex 3
Title : Sender Program..
Author :Aslam Jainul
*/
import java.io.*;
import java.net.*;
import java.util.*;
class sender
{
public static void main(String args[])
{
try
{
int key;
DataInputStream dis=new DataInputStream(System.in);
key=2;
System.out.println("enter the name");
String f=dis.readLine();
File f1=new File(f);
FileReader fr=new FileReader(f1);
Socket s=new Socket("192.168.208.118",8081);
PrintWriter put=new PrintWriter(s.getOutputStream(),true);
put.println(f);
int c=0;
while((c=fr.read())!= -1)
{
put.println(c+key);
}
System.out.println("File content transferred");
fr.close();
s.close();
}
catch(Exception e)
{}
}
}
/*
Exercise : Ex 3
Title : Receiver Program..
Author :Aslam Jainul
*/
import java.io.*;
import java.net.*;
import java.util.*;
class receiver
{
public static void main(String args[]) throws IOException
{
ServerSocket ss;
Socket s;
try
{
System.out.println("waiting for client");
ss=new ServerSocket(8081);
s=ss.accept();
System.out.println("connection established");
BufferedReader get=new BufferedReader(new InputStreamReader(s.getInputStream()));
String fname;
fname=get.readLine();
fname="TR_"+fname;
System.out.println("file name is:"+fname);
File f=new File(fname);
FileWriter fw=new FileWriter(f);
String c;
while((c=get.readLine())!=null)
fw.write(Integer.parseInt(c));
System.out.println("received content stored");
fw.close();
s.close();
}
catch(Exception e)
{}
}
}
/*
Exercise : Ex 3
Title : Decrypt File
Author :Aslam Jainul
*/
import java.io.*;
import java.net.*;
import java.util.*;
class decript
{
public static void main(String args[])
{
try
{
DataInputStream dis=new DataInputStream(System.in);
System.out.println("Enter the encrypted file name with extension");
String fname=dis.readLine();
File f1=new File(fname);
FileReader fr=new FileReader(f1);
File f2=new File("dec_"+fname);
FileWriter fw=new FileWriter(f2);
int c=0;
while((c=fr.read())!=-1)
{
System.out.println(c-2);
fw.write(c-2);
}
fr.close();
fw.close();
}
catch(Exception e)
{}
}
}