还是直接上代码吧~
function _long2str(v, w)
local len = #v
local n = bit.lshift((len - 1) , 2)
if (w) then
local m = v [len]
if ((m < n - 3) or (m > n)) then
return false
end
n = m
end
local s = {}
for i = 1 , len do
s [i] = string.packL(v[i])
end
if (w) then
return string.sub(table.concat(s, ''), 0, n)
else
return table.concat(s, '')
end
end
function _str2long(s, w)
local v = string.unpackL(s .. string.rep("\0", (4 - bit.band((string.len(s) % 4) , 3))))
if (w) then
v [#v+1] = string.len(s)
end
return v
end
function _int32(n)
while (n >= 2147483649) do
n = n - 4294967296
end
while (n <= -2147483649) do
n = n + 4294967296
end
return n
end
function security.xxTEAEncrypt(str, key, toBase64)
toBase64 = toBase64 or true
if (str == "") then
return ""
end
local v = _str2long(str, true)
local k = _str2long(key, false