Hello,
I want to convert a plain text string to binary data so that the readable text is no longer visible, however certain programs can interpret the binary data properly.
Something like when we compile a program into a class, the code is no longer readable, but JVM can still read it.
I'm not making a compiler of some kind, just need to convert text to binary data, then write this data to a file.
Please tell me how to do this.
Thanks

you might be talking about data encryption. There are so many encryption algorithms.. Choose any one encryption algorithm and encrypt the data.

The easiest way is to convert each character to a hexadecimal representation of the original text, and write that to disc. The only downside to this is that the size doubles. IE, 10 characters of input data will result in 20 characters of output data. To read it back, you read 2 characters at a time, and then convert that to an integer value, cast to a char, and append that to a string. The actual coding for this I leave to you. Once you make an effort to code it, we will be happy to help with any problems you may have.

rubberman: don't forget that Java chars are Unicode, 16 bits per char, four hex digits not two.

True enough James - thanks for the reminder! So, you may have to do some additional bit-twiddling to do that. In C/C++ this is pretty standard cruft... :-)

Hello,
Encryption and hex may not work in this case, because the program that "re-reads" the data is a third party tool and I cannot change its code to match my encryption.
I know it can process binary data, so I'm trying for binary output.
I got a string, which gets converted to binary data and then written to a file. This is all I need.
Please post some code.
Thank you

Almost all programs read binary data, but it's not all the same binary data and they don't all use it in the same way. No matter how you generate the binary data it may not work in this case because the program needs some specific binary data to do what you want it to do.

Unless you explain more about the program that processes the binary data and what you expect it to do with the binary data, there is no hope of anyone being able to really help you.

I'm trying to convert a php code to binary format, and then pass it through zend optimizer which can process binary data.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.