Hi,
I'm trying to implement the DES encryption in Java. I have a couple of
concerns at the moment. The first is if I am importing a text file
how do i implement this in a binary or hexidecimal format. I've looked
through the api specifications but am not sure how to go about
it.
Secondly, I'm thinking of using the bigInteger class in order to implement
left shifts towards the end of the algorithm. Is this viable, as it
has a left shift method already included .. or is there a simpler way . .??
Any help would be appreciated ..
Kind Regards,
Matt
Michael Amling - 08 Apr 2004 14:03 GMT
> I'm trying to implement the DES encryption in Java. I have a couple of
> concerns at the moment. The first is if I am importing a text file
[quoted text clipped - 5 lines]
> left shifts towards the end of the algorithm. Is this viable, as it
> has a left shift method already included .. or is there a simpler way . .??
You don't need BigInteger to do left shifts. The 64-bit long type is
plenty for DES.
long number, shifted;
number=whatever();
shifted=number<<12;
--Mike Amling
Michael Amling - 08 Apr 2004 14:09 GMT
> I'm trying to implement the DES encryption in Java.
Wouldn't AES be a better idea?
> I have a couple of
> concerns at the moment. The first is if I am importing a text file
> how do i implement this in a binary or hexidecimal format. I've looked
> through the api specifications but am not sure how to go about
> it.
I'm not sure what you're asking. It's trivial to read the data into a
byte array. And most encryption implementations will encrypt data in a
byte array. What's the problem?
--Mike Amling
Smegly - 09 Apr 2004 04:28 GMT
What I mean is that the text file might have as it's contents for example
"testing des encryption"
How do i read that into a byte array then .. (in order to get it's binary
representation)
Matt
> > I'm trying to implement the DES encryption in Java.
>
[quoted text clipped - 11 lines]
>
> --Mike Amling
Michael Amling - 09 Apr 2004 14:37 GMT
> What I mean is that the text file might have as it's contents for example
> "testing des encryption"
>
> How do i read that into a byte array then .. (in order to get its binary
> representation)
byte[] buffer=new byte[1024];
FileInputStream source=new FileInputStream("mytest.txt");
while (true) {
int howmany=source.read(buffer);
if (howmany<=0) {
break;
}
// Encrypt buffer[0..howmany-1] here
}
Note that it doesn't matter whether "mytest.txt" contains ASCII text,
EBCDIC text, binary data, machine instructions, random bytes, whatever...
--Mike Amling
Roedy Green - 09 Apr 2004 22:41 GMT
>The first is if I am importing a text file
>how do i implement this in a binary or hexidecimal format. I've looked
>through the api specifications but am not sure how to go about
If the final result is binary bytes, you can make them printable with
base64. This process is often called "ascii armouring"
See http://mindprod.com/jgloss/base64.html
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Roedy Green - 09 Apr 2004 22:43 GMT
>how do i implement this in a binary or hexidecimal format
to convert hex <-> byte[] see http://mindprod.com/jgloss/hex.html
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Roedy Green - 09 Apr 2004 22:44 GMT
>The first is if I am importing a text file
>how do i implement this in a binary or hexidecimal format. I've looked
>through the api specifications but am not sure how to go about
>it.
if you just want to read the file (text, binary etc) as if it were a
stream of raw bytes, see http://mindprod.com/fileio.html
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.