How can i make a text encoder/decoder?

im trying to create my encoder/decoder (like base64), anybody can help me ?

3 Likes

You can do a number of things, you can split it up and add random letters inbetween each one.

The easiest way is to make multiple arrays.
One array will contain your basic alphabet.

Then when ylu check each letter you will find its location in the array and take the same index number and change your letter with one from the jumbled array.

The inverse can be done to decode

Check out string.byte and string.char, could be useful for this

1 Like

@rokoblox5 Hey, you made a typo. Did you mean string.byte?

As he said, you can use string.byte and string.char.

Check this out for help: string | Documentation - Roblox Creator Hub

I actually did found an useful function a couple of days ago, to do base64 encoding or decoding. I believe this is probably what you will be looking for, as your Post states.

local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' -- You will need this for encoding/decoding
-- encoding
function enc(data)
    return ((data:gsub('.', function(x) 
        local r,b='',x:byte()
        for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
        return r;
    end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
        if (#x < 6) then return '' end
        local c=0
        for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
        return b:sub(c+1,c+1)
    end)..({ '', '==', '=' })[#data%3+1])
end

-- decoding
function dec(data)
    data = string.gsub(data, '[^'..b..'=]', '')
    return (data:gsub('.', function(x)
        if (x == '=') then return '' end
        local r,f='',(b:find(x)-1)
        for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
        return r;
    end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
        if (#x ~= 8) then return '' end
        local c=0
        for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end
            return string.char(c)
    end))
end
11 Likes

Byte isnt much good as it can have a ton of issues with decoding. For encoding it would be fine. But should you actually want to use the data than it could potentially cause a few issues.

oh thanks guys :ok_hand: :grinning:

1 Like