Advertisement
CaptainSpaceCat

uEncrypt

Jun 24th, 2015
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.37 KB | None | 0 0
  1. local tArgs = {...}
  2. local eRegex, regexNum
  3.  
  4. local function algorithmGen()
  5.     local alg = {}
  6.     repeat
  7.         alg[1] = math.random(0, 9)
  8.         alg[2] = math.random(-9, 0)
  9.         alg[3] = math.random(1, 2)
  10.         alg[4] = alg[3] == 1 and 2 or 1
  11.     until alg[1] + alg[2] ~= 0
  12.     return alg
  13. end
  14.  
  15. function delgorithmGen()
  16.     local rFile = fs.open(tArgs[1], "r")
  17.     byteFile = rFile.readAll()
  18.     rFile.close()
  19.     local regex = {byteFile:find("([+-]?%d)([+-]?%d)(%d)(%d)$")}
  20.     local sFile = fs.open(tArgs[1], "w")
  21.     sFile.write(byteFile:sub(1, -(#tostring(regex[1]) + #tostring(regex[2]) + 3)))
  22.     sFile.close()
  23.     for i = 1, 2 do
  24.         table.remove(regex, 1)
  25.     end
  26.     return regex
  27. end
  28.  
  29. if tArgs[2] == "u" then
  30.     regexNum = delgorithmGen()
  31. else
  32.     eRegex = algorithmGen()
  33. end
  34.  
  35. local uFile = fs.open(tArgs[1], "rb")
  36. local eCode = ""
  37. while true do
  38.     local bData = uFile.read()
  39.     if bData then
  40.         if tArgs[2] == "u" then
  41.             if regexNum[3] == 1 then
  42.                 bData = bData - regexNum[1] - regexNum[2]
  43.             else
  44.                 bData = bData - regexNum[2] - regexNum[1]
  45.             end
  46.         else
  47.             bData = bData + eRegex[eRegex[3]] + eRegex[eRegex[4]]
  48.         end
  49.         eCode = eCode .. string.char(bData)
  50.     else
  51.         break
  52.     end
  53. end
  54. uFile.close()
  55.  
  56. local sFile = fs.open(tArgs[1], "w")
  57. sFile.write(eCode)
  58. if tArgs[2] ~= "u" then
  59.     sFile.write(tostring(eRegex[1]) .. tostring(eRegex[2]) .. tostring(eRegex[3]) .. tostring(eRegex[4]))
  60. end
  61. sFile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement