function getIndex(stringIn,tableOut)
for k,v in ipairs(tableOut) do
if stringIn == v then
return k
end
end
return false
end
function defChar()
local charset = {}
charset.lower = ' abcdefghijklmnopqrstuvwxyz'
charset.upper = string.upper(charset.lower)
charset.number = '0123456789'
local fullcharset = charset.lower .. charset.upper .. charset.number
local chartbl = {}
for echChar in string.gmatch(fullcharset,'%Z') do
table.insert(chartbl,echChar)
end
return chartbl
end
function ver(table, str)
for k,v in ipairs(table) do
if str == v then
return true
end
end
return false
end
local charset = defChar()
local cryptset = {}
for i=1,#charset do
while true do
local bct = string.char(math.random(33,126))
if not ver(cryptset,bct) then
table.insert(cryptset,bct)
break
end
end
end
return charset, cryptset
end
function encrypt(str, key)
local alfabeto, encrypt = getCrypt(key)
local encryptedStr = ''
local strtbl = {}
for ecchi in string.gmatch(str, '%Z') do
table.insert(strtbl, ecchi)
end
for k,v in ipairs(strtbl) do
local jcheck = getIndex(v,alfabeto)
if jcheck then
encryptedStr = encryptedStr .. encrypt[jcheck]
end
end
return encryptedStr
end
function decrypt(str, key)
local alfabeto, encrypt = getCrypt(key)
local decryptedStr = ''
local strtbl = {}
for ecchi in string.gmatch(str, '%Z') do
table.insert(strtbl, ecchi)
end
for k,v in ipairs(strtbl) do
local jcheck = getIndex(v,encrypt)
if jcheck then
decryptedStr = decryptedStr .. alfabeto[jcheck]
end
end