STRING模块新增两个编解码函数

This commit is contained in:
MrZ626
2021-07-29 15:26:37 +08:00
parent 8fb8352c8d
commit e016a20c21

View File

@@ -2,6 +2,7 @@ local data=love.data
local STRING={}
local int,format=math.floor,string.format
local find,sub,upper=string.find,string.sub,string.upper
local char,byte=string.char,string.byte
do--function STRING.shiftChar(c)
local shiftMap={
@@ -81,6 +82,33 @@ do--function STRING.urlEncode(s)
end
end
function STRING.vcsEncrypt(text,key)
local keyLen=#key
local result=""
local buffer=""
for i=0,#text-1 do
buffer=buffer..char((byte(text,i+1)-32+byte(key,i%keyLen+1))%95+32)
if #buffer==26 then
result=result..buffer
buffer=""
end
end
return result..buffer
end
function STRING.vcsDecrypt(text,key)
local keyLen=#key
local result=""
local buffer=""
for i=0,#text-1 do
buffer=buffer..char((byte(text,i+1)-32-byte(key,i%keyLen+1))%95+32)
if #buffer==26 then
result=result..buffer
buffer=""
end
end
return result..buffer
end
function STRING.readLine(str)
local p=str:find("\n")
return str:sub(1,p-1),str:sub(p+1)