Works perfectly so far! I gave it one of my testing methods and let it run on loop for a couple minutes. No problems at all! Thanks for the fix Steve.
I'll post my test program for those interested. It just generates random data strings and check the original size and content with the decoded size and content. If there's a change then say so and stop. Hasn't stopped yet.
On a side note, I have updated my Base85 functions on the first post to use CVL/MKL$ to do some dirty work, removing some calculations and code bloat. A little faster, a little smaller.
- Dav
Edit: Fixed a typo in code. Try'er again.
I'll post my test program for those interested. It just generates random data strings and check the original size and content with the decoded size and content. If there's a change then say so and stop. Hasn't stopped yet.
On a side note, I have updated my Base85 functions on the first post to use CVL/MKL$ to do some dirty work, removing some calculations and code bloat. A little faster, a little smaller.
- Dav
Edit: Fixed a typo in code. Try'er again.
Code: (Select All)
'Testing Steve's functions. Passed with flying colors.
_ControlChr Off
Do
Cls
Color 15: Print "Checking bytes loop -- Hit any key to stop checking ..."
a$ = ""
Print
Color 7, 0: Print "Original:"
For i = 0 To 200
a$ = a$ + Chr$(Int(Rnd * 255))
Next
Print a$
Print Len(a$); "bytes"
Print
Print "Encoded:"
a2$ = B256to128$(a$): Print a2$
Print Len(a2$); "bytes"
Print
Print "Decoded:"
a3$ = B128to256$(a2$): Print a3$
Print Len(a3$); "bytes"
Print
If Len(a$) <> Len(a3$) Then Print "Size don't match!"; t: End
If a$ <> a3$ Then Print "Bytes don't match!"; t: End
_Limit 25
If _KeyHit Then Exit Do
Loop
Color 15: Print "No Problems detected! Original and Decoded data are the same!"
Function B256to128$ (text$)
For i = 1 To Len(text$)
a = Asc(text$, i) ' get the ASCII value of our character
b$ = Right$("00000000" + _Bin$(a), 8) ' convert it to binary
temp$ = temp$ + b$ ' add the binary to a single long string
Next
padding$ = String$(7 - Len(temp$) Mod 7, "0")
temp$ = temp$ + padding$ ' add necessay padding to make it suitable for base-128 encoding
For i = 1 To Len(temp$) Step 7
c$ = Mid$(temp$, i, 7) ' get 7 characters from our 8 byte represention
c = Val("&B" + c$) ' that's the character value of our base 128-character
temp1$ = temp1$ + Chr$(c + 65) ' add that to our new string
Next
B256to128$ = temp1$
End Function
Function B128to256$ (text$)
For i = 1 To Len(text$)
a = Asc(text$, i) - 65
b$ = Right$("0000000" + _Bin$(a), 7)
temp$ = temp$ + b$
Next
temp$ = Left$(temp$, 8 * Int(Len(temp$) / 8)) 'remove padding
For i = 1 To Len(temp$) Step 8
b$ = "&B" + Mid$(temp$, i, 8)
temp1$ = temp1$ + Chr$(Val(b$))
Next
B128to256$ = temp1$
End Function