hi
there are serveral ways on encryption-some standard or you can have your own algorithm.Standard encryption follow elaborate algorithms for which you will have to refer to books or sites on data encryption. However for simple uses, you can create your own algorithms.For example you can develop your algorithm where the characters are encrypted based on their position in the file and also based on the password. Her is a simple code to show you how encrypt a file "testfile.xyz" to "testfile.enc":
<code>
void encrypt(
String password)
{
int currentchar;
int pos=0,passwordpos=0;
FileInputStream fis=new FileInputStream("testfile.xyz");
FileOutputStream fous=new FileOutputstream("testfile.enc");
//read the file character by character. let the current
//character read be in variable 'currentchar'
while((currentchar=fis.read())!=-1)
{
//encrypt the character with a simple algorithm
currentchar = currentchar+pos+ password.charAt( passwordpos );
pos++;
passwordpos++;
passwordpos=passwordpos%password.length();
fos.write(c);
}
}
</code>
To decrypt simply change the line
currentchar=currentchar+pos+password.charAt(passwordpos);
to
currentchar=currentchar-pos-password.charAt(passwordpos);
The encrpyted file cannot be easily decrypted even if one knows the algorithm (even the programmer) since the algorithm is also a function of the password. So the password has to be known to decrpyrt it.You can develope more comlpex algorithms yourself
hope this helps
Tanveer Rameez
[This message has been edited by Rahul Mahindrakar (edited January 04, 2001).]