DES algorithm (Read and Write bytes to file)
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:
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
DES is not 64 bit keylength
Quote:
Originally Posted by
Norm
I have a hard time understanding how that works. As a programmer, It seems like a very hard way to do it. Perhaps the OP has misunderstood how the algorithm works.
Yes, what OP should do is take a hash of the string and store that: Quote:
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.
I tried that a few days ago, got null pointer. I went back and used KeyGenerator in java.security specifiying the keysize given in the DES documentaton in Java. I do not have the cryptographic skills to test whether I was doing data protection but the null pointer went away.
Hint to original poster: Study you decsion 8bytes (64bits) in the available documentation for DES. While you are at it, consider using a hash of the String as the stored information.