Encryption using DES
Hi
I am using DES to encrypt text files and decrypt them back successfully
But if I use the same Algorithms with word or MS Excel documents
The decryption stage does not brig back the file into its original state ?
Please advise if there is a special way to use DES with MS documents
Thanks
[327 byte] By [
B747newa] at [2007-11-26 22:51:22]

> Please advise if there is a special way to use DES> with MS documents> No! Your code must be in corrupting the files.
> No! Your code must be in corrupting the files. May be ...But howcome encrypting and decrypting any text file is no problem ?
You probably didn't realize that DES works on bytes, not chars, and corrupted your data by using Readers and Writers on it. Stick to InputStreams and OutputStreams.
> Stick to InputStreams and> OutputStreams.Will do thanks for the tip
> You probably didn't realize that DES works on bytes,
> not chars, and corrupted your data by using Readers
> and Writers on it. Stick to InputStreams and
> OutputStreams.
Which I did
it works ok with text file
but using word document file the bites are in different bit sizes some are 32 bits DES uses 64 bit for encryption.
If we have 3 MBytes then it would take very lOOOOOOOOOOOOng time to encrypt or decrypt.
any idea on how to Optimise
Thx
> > You probably didn't realize that DES works on
> bytes,
> > not chars, and corrupted your data by using
> Readers
> > and Writers on it. Stick to InputStreams and
> > OutputStreams.
>
>
> Which I did
> it works ok with text file
> but using word document file the bites are in
> different bit sizes some are 32 bits DES uses 64
> bit for encryption.
> If we have 3 MBytes then it would take very
> lOOOOOOOOOOOOng time to encrypt or decrypt.
>
> any idea on how to Optimise
>
I don't understand what you mean by "the bites are in different bit sizes some are 32 bits DES uses 64 bit for encryption". What do you mean by 'bites'?
Unless you are trying to DES encrypt a byte a a time, I can't imagine what you can be doing to take a long time. It takes less than a second for me to DES encrypt a 3MByte file using the JCE.
Post your code!
For almost all practical purposes a "byte" means "eight bits". Certainly that applies here.A Word document is just a collection of eight bit values (bytes). If your code is treating a Word document differently from any other file then your code is wrong.
> For almost all practical purposes a "byte" means
> "eight bits". Certainly that applies here.
>
> A Word document is just a collection of eight bit
> values (bytes). If your code is treating a Word
> document differently from any other file then your
> code is wrong.
Sorry I ment to say byte
however , I have read some bytes from the file in byte []bt array
using the following
// find out howmany bits in every byte
for ( int n = 0 ; n < bt.length ; n++){
int v = bt[n] ;
String binstr = Integer.toBinaryString(v);
System.out.print ("\n" + new String(binstr) + "{ # bits is : "+ binstr.length()+" }");
}
And that what I have
THE NUMBER OF BYTES IN THE FILE IS >>> : 24064
11111111111111111111111111010000{ # bits is : 32 }
11111111111111111111111111001111{ # bits is : 32 }
10001{ # bits is : 5 }
11111111111111111111111111100000{ # bits is : 32 }
11111111111111111111111110100001{ # bits is : 32 }
11111111111111111111111110110001{ # bits is : 32 }
11010{ # bits is : 5 }
11111111111111111111111111100001{ # bits is : 32 }
0{ # bits is : 1 }
0{ # bits is : 1 }
0{ # bits is : 1 }
0{ # bits is : 1 }
0{ # bits is : 1 }
0{ # bits is : 1 }
0{ # bits is : 1 }
0{ # bits is : 1 }
0{ # bits is : 1 }
0{ # bits is : 1 }
0{ # bits is : 1 }
0{ # bits is : 1 }
0{ # bits is : 1 }
0{ # bits is : 1 }
0{ # bits is : 1 }
0{ # bits is : 1 }
111110{ # bits is : 6 }
0{ # bits is : 1 }
11{ # bits is : 2 }
0{ # bits is : 1 }
11111111111111111111111111111110{ # bits is : 32 }
11111111111111111111111111111111{ # bits is : 32 }
1001{ # bits is : 4 }
0{ # bits is : 1 }
//Appending '0'to byte ? to make it to 32 bits ?
This is absolute rubbish. It make no sense at all. It has no relevance to encryption using DES.
> And that what I have
What you're looking at isn't bytes. As I said before, a byte is eight bits. It's always eight bits. If it's not eight bits then it's not a byte.
And what you're looking at are integers.
What's happening here is that you're converting bytes (eight bit values) to integers (signed 32 bit values) and then converting those into a String representing the bit values of the integer.
That doesn't print leading zeros for exactly the same reason that we would write 42 instead of 000042. The values with large numbers of leading ones are because you're converting an arbitrary byte value into a negative integer (if the first bit of the byte is set the integer conversion treats it as a negative value).
I think you've bitten off more than you can chew with this DES stuff. You need to study the basics in a bit more depth.
> I think you've bitten off more than you can chew with
> this DES stuff. You need to study the basics in a bit
> more depth.
yes You are right may be it was a big BYTEfor me ...
But the main issue is not to give up ..... otherwise you will choke ...
so I have Chewed it upbit by bit for 8 bits untill I solved the problem
DES is now working fine for all type of files
Thanks again for the hints