GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2021-06-10 03:08:08

maras
Member
Registered: 2021-04-25
Posts: 22
Website

base64 URL encode / decode

Might be useful for people using HTTP stuff
Works just like regular base64 but with characters that can be used in URL

Expand/// base64url_encode(string)
//
// returns encoded string
//
//     s    string to encode, string
//
/// GMLscripts.com/license

function base64url_encode(s) {
    s = base64_encode(string(s));
    s = string_replace_all(s, "/", "_");
    s = string_replace_all(s, "=", "");
    s = string_replace_all(s, "+", "-");
    return s;
}
Expand/// base64url_decode(string)
//
// returns decoded string
//
//     s    string to decode, string
//
/// GMLscripts.com/license

function base64url_decode(s) {
    s = string(s);
    s = string_copy(s + "===", 0, string_length(s) + (string_length(s) % 4));
    s = string_replace_all(s, "_", "/");
    s = string_replace_all(s, "-", "+");
    return base64_decode(s);
}

Last edited by maras (2021-06-11 02:33:33)

Offline

#2 2021-06-17 10:39:34

xot
Administrator
Registered: 2007-08-18
Posts: 1,238

Re: base64 URL encode / decode

Thanks. After looking into this issue some I think this is probably the best way to go. I will be making some very minor tweaks but it will function the same.


Abusing forum power since 1986.

Offline

Board footer

Powered by FluxBB