KananGamer

[TFM-LUA] Save/Load system

Aug 30th, 2018
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.97 KB | None | 0 0
  1. --[[
  2.     Author(s): Nettoork#0000
  3.     Version: 1.3
  4. ]]--
  5.  
  6. table.encrypt = function(tableC, password, password2)
  7.     if not tableC or not password or not password2 or type(tableC) ~= 'table' or password == '' or password2 == '' then return end
  8.     local initSeed, finalString, newMessage, key = '', '', '', ''
  9.     for i in password:gmatch('.') do
  10.         initSeed = initSeed..i:byte()
  11.     end
  12.     for i in password2:gmatch('.') do
  13.         key = key..i:byte()
  14.     end
  15.     math.randomseed(initSeed)
  16.     otherSeed = math.random(1000000)
  17.     local action = pcall(function()
  18.         for i, v in next, tableC do
  19.             if type(v) == 'string' or type(v) == 'number' then
  20.                 if type(v) == 'string' then
  21.                     v = [[']]..v..[[']]
  22.                 end
  23.                 newMessage = newMessage..' '..v..' '..i:upper()
  24.             else
  25.                 return
  26.             end
  27.         end
  28.         newMessage = newMessage..' '..key
  29.         for i in newMessage:gmatch('.') do
  30.             local newByte = i:byte() + 68 + math.random(5)
  31.             otherSeed = otherSeed + i:byte()
  32.             math.randomseed(otherSeed)
  33.             if (newByte >= 65 and newByte <= 122) and not (newByte >= 91 and newByte <= 96) then
  34.                 newByte = string.char(newByte)
  35.             end
  36.             finalString = finalString..newByte
  37.         end
  38.     end)
  39.     math.randomseed(os.time())
  40.     if not action then
  41.         return
  42.     else
  43.         return finalString
  44.     end
  45. end
  46.  
  47. table.decrypt = function(stringC, password, password2)
  48.     if not stringC or not password or not password2 or type(stringC) ~= 'string' or password == '' or password2 == '' then return end
  49.     local initSeed, finalString, aByte, key = '', '', '', ''
  50.     for i in password:gmatch('.') do
  51.         initSeed = initSeed..i:byte()
  52.     end
  53.     for i in password2:gmatch('.') do
  54.         key = key..i:byte()
  55.     end
  56.     math.randomseed(initSeed)
  57.     otherSeed = math.random(1000000)
  58.     local action = pcall(function()
  59.         for i in stringC:gmatch('.') do
  60.             if i:byte() >= 65 and i:byte() <= 122 then
  61.                 local newByte = i:byte() - 68 - math.random(5)
  62.                 otherSeed = otherSeed + newByte
  63.                 math.randomseed(otherSeed)
  64.                 finalString = finalString..string.char(newByte)
  65.             else
  66.                 aByte = aByte..i
  67.                 if aByte:len() >= 3 then
  68.                     local newByte = tonumber(aByte) - 68 - math.random(5)
  69.                     otherSeed = otherSeed + newByte
  70.                     math.randomseed(otherSeed)
  71.                     finalString = finalString..string.char(newByte)
  72.                     aByte = ''
  73.                 end
  74.             end
  75.         end
  76.     end)
  77.     math.randomseed(os.time())
  78.     if not action then
  79.         return
  80.     else
  81.         local finalTable, stage, fsLength, aString, aNumber = {}, 0, 0
  82.         for i, v in string.gmatch(finalString, '[^%s]+') do
  83.             fsLength = fsLength + 1
  84.         end
  85.         for i, v in string.gmatch(finalString, '[^%s]+') do
  86.             stage = stage + 1
  87.             if stage == fsLength and i ~= key then
  88.                 return
  89.             elseif aString then
  90.                 if aString:sub(-1) == [[']] then
  91.                     finalTable[i:lower()] = aString:gsub([[']], '')
  92.                     aString = nil
  93.                 else
  94.                     aString = aString..' '..i
  95.                 end
  96.             elseif aNumber then
  97.                 finalTable[i:lower()] = aNumber
  98.                 aNumber = nil
  99.             elseif i:sub(1, 1) == [[']] then
  100.                 aString = i
  101.             else
  102.                 aNumber = i
  103.             end
  104.         end
  105.         return finalTable
  106.     end
  107. end
Advertisement
Add Comment
Please, Sign In to add comment