Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Working on Base-85 Encoder/Decoder Functions
#12
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. Smile

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

Find my programs here in Dav's QB64 Corner
Reply


Messages In This Thread
RE: Working on Base-85 Encoder/Decoder Functions - by Dav - 09-23-2023, 06:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  new approach to base conversion system and math library Dragoncat 2 592 07-16-2025, 10:19 PM
Last Post: Dragoncat
  universal base conversion program possibly for a base conversion library later on Dragoncat 22 3,098 04-24-2025, 02:08 AM
Last Post: Dragoncat
  read 2 or more USB mice on one PC - fully working with keyboard input madscijr 2 1,114 06-16-2024, 01:48 AM
Last Post: madscijr
  Working on ways to map images onto balls Dav 1 758 10-05-2023, 12:12 AM
Last Post: PhilOfPerth
  Working on the Doodle Drawing Recorder/Player. Testers wanted Dav 16 3,760 09-12-2023, 02:58 AM
Last Post: Dav

Forum Jump:


Users browsing this thread: 1 Guest(s)