diff --git a/Zframework/stringExtend.lua b/Zframework/stringExtend.lua index 2e5d834a..27783cdf 100644 --- a/Zframework/stringExtend.lua +++ b/Zframework/stringExtend.lua @@ -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)