Well in VB we can change the String into Bytearray very easily like
Dim A() as Byte
A()=StrConv("String",vbUnicode)
But how to do it in PB ?
I have a lot of trouble with this
Tried MultiByteToWideChar But need to String into ByteArray Please help me
String to ByteArray
Re: String to ByteArray
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Re: String to ByteArray
Thank You c4s
Have seen that before well dont know but this is function im trying to Code in PB
Want to convert to PB
This is wat i have done
Debug X("d","d")
It says out of bounds etc
Can any one correct this please
im sure im doing a lot of mistakes

Code: Select all
Public Function X(ByVal T As String, p As String) As String
On Error Resume Next
Dim s(0 To 255) As Integer
Dim i, B, c As Integer
Dim L() As Byte
Dim R() As Byte
Dim D As Byte
R() = StrConv(T, vbFromUnicode)
L() = StrConv(p, vbFromUnicode)
For i = 0 To 255
s(i) = i
Next i
For i = 0 To 255
D = s(i)
s(i) = s((B + s(i) + L(i Mod Len(p))) Mod 256)
s((B + s(i) + L(i Mod Len(p))) Mod 256) = D
Next i
B = 0
For i = 0 To UBound(R)
c = (c + s((B + 1) Mod 256)) Mod 256
s((B + 1) Mod 256) = s(c)
s(c) = s((B + 1) Mod 256)
R(i) = R(i) Xor (s((s((B + 1) Mod 256) + s(c)) Mod 256))
Next i
X = StrConv(R(), vbUnicode)
End Function
This is wat i have done
Code: Select all
Structure ByteArray1
R.b[0]
EndStructure
Structure ByteArray2
L.b[0]
EndStructure
Procedure.s X(T.s, p.s)
;On Error Resume Next
Dim s.i(255)
i.i
B.i
c.i
D.b
;R() = StrConv(T, vbFromUnicode)
;L() = StrConv(p, vbFromUnicode)
*MemoryR.ByteArray1 = @T
*MemoryID.ByteArray2 = @p
For i = 0 To 255
s(i) = i
Next i
For i = 0 To 255
D = s(i)
s(i) = s((B + s(i) + *MemoryID\L[i % Len(p)]) % 256)
s((B + s(i) + *MemoryID\L[i % Len(p)]) % 256) = D
Next i
B = 0
For i = 0 To SizeOf(*MemoryR\R)
c = (c + s((B + 1) % 256)) % 256
s((B + 1) % 256) = s(c)
s(c) = s((B + 1) % 256)
*MemoryR\R[i] = *MemoryR\R[i] XOr (s((s((B + 1) % 256) + s(c)) % 256))
Next i
ProcedureReturn T
EndProcedure
It says out of bounds etc
Can any one correct this please
im sure im doing a lot of mistakes
Re: String to ByteArray
Hi,
again strange stuff in your original code:
In my opinion B is always 0.
But here is a working code:
S went to a negative value.
So I have changed it from .i to .u
again strange stuff in your original code:
In my opinion B is always 0.
But here is a working code:
Code: Select all
Structure ByteArrayStr
b.b[0]
EndStructure
Procedure.s X(T.s, p.s)
Dim s.u(255)
Define i.i
Define B.i
Define c.i
Define D.b
;R() = StrConv(T, vbFromUnicode)
;L() = StrConv(p, vbFromUnicode)
*MemoryR.ByteArrayStr = @T
*MemoryL.ByteArrayStr = @p
For i = 0 To 255
s(i) = i
Next i
For i = 0 To 255
D = s(i)
s(i) = s((B + s(i) + *MemoryL\b[i % Len(p)]) % 256)
Debug s(i)
Debug (B + s(i) + *MemoryL\b[i % Len(p)]) % 256
s((B + s(i) + *MemoryL\b[i % Len(p)]) % 256) = D
Next i
B = 0
Help = Len(T)
For i = 0 To Help
c = (c + s((B + 1) % 256)) % 256
s((B + 1) % 256) = s(c)
s(c) = s((B + 1) % 256)
*MemoryR\b[i] = *MemoryR\b[i] ! (s((s((B + 1) % 256) + s(c)) % 256))
Next i
ProcedureReturn T
EndProcedure
Debug X("d","d")
So I have changed it from .i to .u
Re: String to ByteArray
Hi,
I changed the above code.
The sizeof() was wrong in the last for loop.
I changed the above code.
The sizeof() was wrong in the last for loop.
Re: String to ByteArray
whoa
that was fast thanks :d Works
thanks again

thanks again