Official Site

click here to view our new site launched

Pages

Thursday, August 19, 2010

Simple Encryptor

" An encryptor converts meaningful information into gibbrish form so that it is safe from the eyes of unauthorized people "
import javax.swing.*;
import java.io.*;
public class encrypt
{
public static void main(String arg[]) throws FileNotFoundException, IOException
{
String choice = JOptionPane.showInputDialog("Encrypt(E)/Decrypt(D)");
String file= JOptionPane.showInputDialog("File Name:");
File usrfile = new File(file);
File encfile = new File("enc.txt");
encfile.createNewFile();
BufferedWriter userStream = new BufferedWriter( new FileWriter(encfile));
try
{
PushbackReader in = new PushbackReader( new BufferedReader ( new FileReader(usrfile)));
int c=-4,i=0,temp=0;
while(c!=-1)
{
c=in.read();
temp=c;
if(c==-1)break;
if(choice.equals("e")||choice.equals("E"))
{
if(temp%2==0)temp+=9;
else temp-=7;
}
else if(choice.equals("d")||choice.equals("D"))
{
if(temp%2!=0)temp-=9;
else temp+=7;
}
userStream.write(String.valueOf((char)temp));
}
in.close();
userStream.close();
usrfile.delete();
File usrfile2 = new File(file);
encfile.renameTo(usrfile2);
}
catch(IOException e)
{
JOptionPane.showMessageDialog(null,e);
}
System.exit(0);
}
}
Execute the above program.
Encrypt(E)/Decrypt(D)
enc2
File Name:
enc3
Sample File
en1
Encrypted File
enc4
To get back the non-gibberish form or decrypted text, execute the code once again and enter d in the first window and file name in the following window.
Note:
  • This code can be used to encrypt/decrypt only files encoded in Text Format
  • The file to be encrypted has to be in the same folder from which the code is executed.
  • Sound knowledge of Java is required to understand and successfully execute the above code.

No comments:

Post a Comment

$2.49 .COM at GoDaddy.com! Expires 5/14/13