Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

DES algorithm (Read and Write bytes to file)

807603Jan 14 2008 — edited Jan 15 2008
Hello everyone,

I'm trying to implement a DES (Data Encryption Standard) algorithm to encrypt and decrypt files. It's all implemented regarding encoding and decoding.

DES algorithm reads 64 bits from file each time and encode them (the process is repeat till the end of file) to the new encrypted file. The decoding process is the opposite but that doesn't matter for this problem.

My problem is the algorithm is all implemented treating bits (0's and 1's) as strings (it's easier I guess). I want to known how can I read, inside a loop, 8bytes (64bits) from file each time and convert them to a string of bits. At the end I want to convert that 64 bits string back to bytes to be able to write them to the encrypted file.

Example code:
while (!EOF) {
   String my64bits = read64BitsFromFile(file.bin);

   encodeBitsString(my64Bits); // This is already done

   writeBitsStringToFile(my64Bits);
}
So anyone can give me an hint on how to read bytes to string (only 0's and 1's) and write them back as bytes? And do it till the EOF?

Thanks in advanced! Cheers
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 12 2008
Added on Jan 14 2008
6 comments
187 views