Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Working on Base-85 Encoder/Decoder Functions
#11
Try this version @Dav :

Code: (Select All)
_CONTROLCHR OFF



test$ = "abc"
a$ = B256to128$(test$)
b$ = B128to256$(a$)
PRINT test$, a$, b$
PRINT LEN(test$), LEN(a$), LEN(b$)

SLEEP

FOR i = 0 TO 255
    t$ = CHR$(i)
    PRINT i, t$,
    a$ = B256to128(t$)
    PRINT a$,
    b$ = B128to256(a$)
    PRINT b$
    IF t$ <> b$ THEN
        PRINT "DON'T MATCH!!"
        END
    END IF
NEXT

PRINT
PRINT "All characters match before and after encoding and decoding."



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

I tried to change and simplify the process as much as possible here.  From the initial testing, all seems to be working now as it should, without that stray "0" popping up from time to time and biting you in the hiney.  

Try it out and let me know if it works as advertised, or not, for you.  Smile
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  new approach to base conversion system and math library Dragoncat 2 577 07-16-2025, 10:19 PM
Last Post: Dragoncat
  universal base conversion program possibly for a base conversion library later on Dragoncat 22 3,039 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,100 06-16-2024, 01:48 AM
Last Post: madscijr
  Working on ways to map images onto balls Dav 1 748 10-05-2023, 12:12 AM
Last Post: PhilOfPerth
  Working on the Doodle Drawing Recorder/Player. Testers wanted Dav 16 3,722 09-12-2023, 02:58 AM
Last Post: Dav

Forum Jump:


Users browsing this thread: 1 Guest(s)