• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

please help me

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to encrypt a given file?please help me in coding.
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
vikram veera
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tanveer Rameez
for sending the code,i will try that code in my home after i will reply you.Please tell me the book and site for data encryption.
so that i can refer.
Tanveer Rameez
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic