1,105,290 Community Members

how to convert plain text to binary data?

Member Avatar
erms
Light Poster
32 posts since Jan 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
harinath_2007
Posting Pro
509 posts since Aug 2010
Reputation Points: 56 [?]
Q&As Helped to Solve: 51 [?]
Skill Endorsements: 4 [?]
 
1
 

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

Member Avatar
rubberman
Senior Poster
3,984 posts since Mar 2010
Reputation Points: 513 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 87 [?]
 
0
 

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.

Member Avatar
JamesCherrill
... trying to help
10,362 posts since Apr 2008
Reputation Points: 2,081 [?]
Q&As Helped to Solve: 1,749 [?]
Skill Endorsements: 47 [?]
Moderator
Featured
 
2
 

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

Member Avatar
rubberman
Senior Poster
3,984 posts since Mar 2010
Reputation Points: 513 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 87 [?]
 
0
 

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... :-)

Member Avatar
erms
Light Poster
32 posts since Jan 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
bguild
Posting Whiz
339 posts since Oct 2012
Reputation Points: 163 [?]
Q&As Helped to Solve: 84 [?]
Skill Endorsements: 8 [?]
 
0
 

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.

Member Avatar
erms
Light Poster
32 posts since Jan 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: