shadedecho
Programmer
OK, I know this may sound like a strange request, but...
Let's say from some location (like an ActiveX object for instance) I'm getting in my JAVASCRIPT a variable that is a binary packed object. This object is guaranteed to be a set of packed bytes, where each byte represents a single printable ascii character, thus the object always has a printable string representation.
If I then pass it to this VBSCRIPT function:
The returned value from this VBSCRIPT function will be the printable string representation of the Binary object in question. As far as I understand things, the above function has no such equivalent in Javascript since Javascript won't let me work with an arbitrary object byte by byte (there's no MidB() function in JS). But, the VBSCRIPT function works just as needed.
So, all that is fine. Now, this is what I am trying to accomplish... I want to actually reverse that process. I want to, in some way, with a combination of VBScript and Javascript, be able to create a binary packed object in the same way such that each byte of it represents a printable ascii character from some arbitrary string.
So, basically I want a function like this:
Which returns the binary object representation of that string.
Now, I am aware that VBSCRIPT doesn't have binary shift operators, but Javascript does, so I am thinking perhaps I will need to combine both JS and VBS for a solution.
I was thinking I would have to do things like obj = ((obj<<8)|nextchar) to shift on characters byte by byte into the object. But the mechanics of how to do this are eluding me.
Anyone have any ideas?
Let's say from some location (like an ActiveX object for instance) I'm getting in my JAVASCRIPT a variable that is a binary packed object. This object is guaranteed to be a set of packed bytes, where each byte represents a single printable ascii character, thus the object always has a printable string representation.
If I then pass it to this VBSCRIPT function:
Code:
Function BinaryToString(Binary)
Dim I,S
For I = 1 to LenB(Binary)
S = S & Chr(AscB(MidB(Binary,I,1)))
Next
BinaryToString = S
End Function
The returned value from this VBSCRIPT function will be the printable string representation of the Binary object in question. As far as I understand things, the above function has no such equivalent in Javascript since Javascript won't let me work with an arbitrary object byte by byte (there's no MidB() function in JS). But, the VBSCRIPT function works just as needed.
So, all that is fine. Now, this is what I am trying to accomplish... I want to actually reverse that process. I want to, in some way, with a combination of VBScript and Javascript, be able to create a binary packed object in the same way such that each byte of it represents a printable ascii character from some arbitrary string.
So, basically I want a function like this:
Code:
Function StringToBinary(str)
Dim BinObj
...
StringToBinary = BinObj
End Function
Which returns the binary object representation of that string.
Now, I am aware that VBSCRIPT doesn't have binary shift operators, but Javascript does, so I am thinking perhaps I will need to combine both JS and VBS for a solution.
I was thinking I would have to do things like obj = ((obj<<8)|nextchar) to shift on characters byte by byte into the object. But the mechanics of how to do this are eluding me.
Anyone have any ideas?