Decode and Encode a Base64 string

I've finally got round to making a Base64 decoder using the information from Base64 Decode Algorithm | Base64 Algorithm | Learn | Base64


It's very naive and takes 22 seconds to decode a 100x100 encoded image on my computer!

So, if anyone fancies improving it (no JS of course) I'd be really grateful :slight_smile:

The final image should look like this (it's a tile of part of an wind map) but the decoder must decode the simple ones as well in order to be compliant



[edit Originally it was taking 300 secs but I'd made a mistake with encoding the data in the 1st place - all OK now - output bytes should be 40,000 long if processing the tile image]

And I don't need it myself at the moment but if someone fancies writing an encoder to go with it that would be very nice :slight_smile:

With conversion 4 => 3 bytes "unrolled" as a single expression.
X mod 2^n - extract n low bits
X / 2^n - drop n low bits
X * 2 ^n - shift left n bit


Wow :slight_smile:
Actually does it in 679ms on mine :slight_smile:

Now going thru it to make see how you've done it [edit - Done that - great idea not to have to convert to binary and then back again :slight_smile: ]

Thank you very much :slight_smile:

Compiled map makes it twice as fast on my computer
base64 decode script pic (9)

I've made a few cosmetic variable name changes, added padding if needed and made a custom reporter out of it.
added in an encoder

I've left the map un-compiled at the moment as I've sometimes had issues with compiled blocks

Thank you once again :slight_smile:


Although the new version
untitled script pic - 2022-05-31T215443.318
is twice as fast as the previous one, it still pales in comparison to JS
untitled script pic - 2022-05-31T215342.536

Because the complied version doesn't yield while its running, I'm not using it on large images

But I've added it as seperate block for anyone who wants to use it


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

I've added an encoder as well
mqttTutorial script pic

to go with the decoders

base64 script pic (1)
base64 script pic