mirror of
https://github.com/rayaman/multi.git
synced 2026-09-05 07:27:35 -04:00
Updated to 1.10.0!
Check changes.md for what was done
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
local base64={}
|
||||
local bs = { [0] =
|
||||
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
|
||||
'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
|
||||
'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
|
||||
'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/',
|
||||
}
|
||||
local bsd=table.flip(bs)
|
||||
local char=string.char
|
||||
function base64.encode(s)
|
||||
local byte, rep, pad = string.byte, string.rep, 2 - ((#s-1) % 3)
|
||||
s = (s..rep('\0', pad)):gsub("...", function(cs)
|
||||
local a, b, c = byte(cs, 1, 3)
|
||||
return bs[bit.rshift(a,2)] .. bs[bit.bor(bit.lshift(bit.band(a,3),4),bit.rshift(b,4))] .. bs[bit.bor(bit.lshift(bit.band(b,15),2),bit.rshift(c,6))] .. bs[bit.band(c,63)]
|
||||
end)
|
||||
return s:sub(1, #s-pad) .. rep('=', pad)
|
||||
end
|
||||
function base64.decode(s)
|
||||
local s=s:match("["..s.."=]+")
|
||||
local p,cc=s:gsub("=","A")
|
||||
local r=""
|
||||
local n=0
|
||||
s=s:sub(1,#s-#p)..p
|
||||
for c = 1,#s,4 do
|
||||
n = bit.lshift(bsd[s:sub(c, c)], 18) + bit.lshift(bsd[s:sub(c+1, c+1)], 12) + bit.lshift(bsd[s:sub(c + 2, c + 2)], 6) + bsd[s:sub(c + 3, c + 3)]
|
||||
r = r .. char(bit.band(bit.arshift(n, 16), 0xFF)) .. char(bit.band(bit.arshift(n, 8), 0xFF)) .. char(bit.band(n, 0xFF))
|
||||
end
|
||||
return r:sub(1,-(cc+1))
|
||||
end
|
||||
return base64
|
||||
@@ -0,0 +1,72 @@
|
||||
local base91={}
|
||||
local b91enc={[0]=
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
||||
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
||||
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '#', '$',
|
||||
'%', '&', '(', ')', '*', '+', ',', '.', '/', ':', ';', '<', '=',
|
||||
'>', '?', '@', '[', ']', '^', '_', '`', '{', '|', '}', '~', '"'
|
||||
}
|
||||
local b91dec=table.flip(b91enc)
|
||||
function base91.decode(d)
|
||||
local l,v,o,b,n = #d,-1,"",0,0
|
||||
for i in d:gmatch(".") do
|
||||
local c=b91dec[i]
|
||||
if not(c) then
|
||||
-- Continue
|
||||
else
|
||||
if v < 0 then
|
||||
v = c
|
||||
else
|
||||
v = v+c*91
|
||||
b = bit.bor(b, bit.lshift(v,n))
|
||||
if bit.band(v,8191) then
|
||||
n = n + 13
|
||||
else
|
||||
n = n + 14
|
||||
end
|
||||
while true do
|
||||
o=o..string.char(bit.band(b,255))
|
||||
b=bit.rshift(b,8)
|
||||
n=n-8
|
||||
if not (n>7) then
|
||||
break
|
||||
end
|
||||
end
|
||||
v=-1
|
||||
end
|
||||
end
|
||||
end
|
||||
if v + 1>0 then
|
||||
o=o..string.char(bit.band(bit.bor(b,bit.lshift(v,n)),255))
|
||||
end
|
||||
return o
|
||||
end
|
||||
function base91.encode(d)
|
||||
local b,n,o,l=0,0,"",#d
|
||||
for i in d:gmatch(".") do
|
||||
b=bit.bor(b,bit.lshift(string.byte(i),n))
|
||||
n=n+8
|
||||
if n>13 then
|
||||
v=bit.band(b,8191)
|
||||
if v>88 then
|
||||
b=bit.rshift(b,13)
|
||||
n=n-13
|
||||
else
|
||||
v=bit.band(b,16383)
|
||||
b=bit.rshift(b,14)
|
||||
n=n-14
|
||||
end
|
||||
o=o..b91enc[v % 91] .. b91enc[math.floor(v / 91)]
|
||||
end
|
||||
end
|
||||
if n>0 then
|
||||
o=o..b91enc[b % 91]
|
||||
if n>7 or b>90 then
|
||||
o=o .. b91enc[math.floor(b / 91)]
|
||||
end
|
||||
end
|
||||
return o
|
||||
end
|
||||
return base91
|
||||
Reference in New Issue
Block a user