Convert Sting

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I convert a string to its binary equivalent?

Any help will be greatly appreciated!
Kevin
 
Kevin said:
How can I convert a string to its binary equivalent?


Now, that sure sounds like a singularly useless exercise.
What are you trying to accomplish?

For what it's worth, each character's character code can be
calculated by using the Asc function. E.g. Asc("A") is 65)
or, if it's more to your needs Hex(Asc("A")) is 41.
 
Marshal,

I am trying to protect users from themselves. I am storing configuration
information in an application I am revising. I have had a "Smart" user try to
modify something in a file containing configuration information where the
user read something he did not understand and thought changing a value would
make things work the way he thought they should. It took me several days of
plugging and his confession to figure out what happened. TO prevent that in
the future I thought I would obscure the information in the file. To obscure
that information I am trying to store the information in a format he can not
read. My other option is to hide the file containing the information, which I
may do as well.

I may use the HEX command. How would I reverse the results of that command?

Thanks!

Kevin
 
"Smart" user(?), I thought that was the definition of an oxymoron <g>.


Function HexString(RHS As String) As String
Dim strRet As String
Dim intCount As Integer

strRet = ""
For intCount = 1 To Len(RHS)
strRet = strRet & Hex(Asc(Mid(RHS, intCount, 1)))
Next
HexString = strRet
End Function

Function StringHex(RHS As String) As String
Dim strRet As String
Dim intCount As Integer

strRet = ""
For intCount = 1 To Len(RHS) Step 2
strRet = strRet & Chr("&H" & Mid(RHS, intCount, 2))
Next
StringHex = strRet
End Function


Sample usage
?hexstring("Kevin")
4B6576696E

?stringhex(hexstring("Kevin"))
Kevin
or
?stringhex("4B6576696E")
Kevin
 
Kevin said:
I am trying to protect users from themselves. I am storing configuration
information in an application I am revising. I have had a "Smart" user try to
modify something in a file containing configuration information where the
user read something he did not understand and thought changing a value would
make things work the way he thought they should. It took me several days of
plugging and his confession to figure out what happened. TO prevent that in
the future I thought I would obscure the information in the file. To obscure
that information I am trying to store the information in a format he can not
read. My other option is to hide the file containing the information, which I
may do as well.


Hide the file with an obscure name, but encrypting it with
this kind of code is probably not a particularly productive
exercise.

Couldn't you make your point more effectively by whapping
the user up side the head with a 2x4 or at least explain
that screwing around with other folks computer files is
cause for dismissal with prejudice ;-)
 
Marshal,

I have thought about wapping him upside the head, but then I would be the
one punished. Firing anyone around here is not impossible, but is very
difficult! I will probably both hide the file and encrypt it. I tried naming
the file with an obscure name and he still figured out which file I was
using. I think he made legal changes within the program then looked for the
file that had just changed. Smart SOB. My plan now is to encrypt the file,
move it and change the name. I will probably move it to a system directory.
Using the code suggested by Terry is not difficult.

Thanks for the help!
 
There are a whole raft of encrypion algorithms on the net if you look or
them. Some of them easily cracked some not so easy to crack.
 
My intent at this point is to make things difficult for someone to screw with
the settings in any way I do not intend. I want to do that in a simple a way
as possible. I am not trying to protect sensitive information, just the
proper function of my program. I think if I make it difficult to find the
file and to know what is being changed, then I have accomplished my task.

Thanks for the help!
 
Terry in the "sample useage" you have a question mark before the function
name. Why? I have never seen that syntax?

?hexstring("Kevin")
4B6576696E

?stringhex(hexstring("Kevin"))
Kevin
or
?stringhex("4B6576696E")
Kevin
 
hi Kevin,
Terry in the "sample useage" you have a question mark before the function
name. Why? I have never seen that syntax?

?hexstring("Kevin")
4B6576696E
It is a BASIC legacy for PRINT (VBA: Debug.? -> Debug.Print).


mfG
--> stefan <--
 
The samples were run in the immediate window (and cut and paste from there),
you use the ? before the function call to show you are expecting a return
value.

--

Terry Kreft


Kevin said:
Terry in the "sample useage" you have a question mark before the function
name. Why? I have never seen that syntax?

?hexstring("Kevin")
4B6576696E

?stringhex(hexstring("Kevin"))
Kevin
or
?stringhex("4B6576696E")
Kevin
 
Back
Top