base64 encoding for embed=

Here you can talk about anything related to BBC BASIC, not covered in another category
artfizz
Posts: 21
Joined: Wed 11 Dec 2024, 17:15

base64 encoding for embed=

Post by artfizz »

I'm puzzled how the base64 encoding (used with the embed= URL parameter of the in-browser version of BBC BASIC for SDL 2.0) handles padding (in cases where the length of the BASIC program is not a multiple of 3) ?

The example program (cited in another thread) given for decoding base64

Code: Select all

dec$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
            F% = OPENOUT(@tmp$ + "untitled")
            FOR I% = 0 TO LENurl$-1 STEP 4
              FOR J% = 1 TO 4
                D% = (D% << 6) + (INSTR(dec$,MID$(url$,I%+J%,1))-1 AND &3F)
              NEXT
              BPUT#F%,D% >> 16:BPUT#F%,D% >> 8:BPUT#F%,D%
            NEXT
            CLOSE #F%
only mentions characters in the set A..Za..z0..9 and - and _ and makes no mention of a padding character.

To put it another way, do I have to write my own base64 encoding utility, or is there one already out there that I can use to generate the input for embed= ?
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Re: base64 encoding for embed=

Post by Richard Russell »

artfizz wrote: Sat 21 Dec 2024, 17:57 only mentions characters in the set A..Za..z0..9 and - and _ and makes no mention of a padding character.
Indeed, it says here that in Base64URL no padding is necessary.