Advertisement
Alakazard12

Encrypt

Nov 11th, 2012
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.70 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. function sep(list, by)
  4.     if string.sub(list, 1, 1) == by then
  5.         list = string.sub(list, 2)
  6.     end
  7.     local newlist = {}
  8.     while true do
  9.         local on = nil
  10.         local done = false
  11.         for i = 1, #list do
  12.             if done == false then
  13.                 if string.sub(list, i, i) == by then
  14.                     on = i
  15.                     done = true
  16.                 end
  17.             end
  18.         end
  19.         if on then
  20.             table.insert(newlist, string.sub(list, 1, on - 1))
  21.             list = string.sub(list, on + 1)
  22.         else
  23.             break
  24.         end
  25.     end
  26.     table.insert(newlist, list)
  27.     return newlist
  28. end
  29.  
  30. function encrypt(path)
  31.     if fs.exists(path) and not fs.isDir(path) then
  32.         local fil = fs.open(path, "r")
  33.         local nr = fil.readAll()
  34.         fil.close()
  35.         local newr = ""
  36.         for i = 1, #nr do
  37.             newr = newr.."\\"..string.byte(string.sub(nr, i, i))
  38.         end
  39.         fs.delete(path)
  40.         local fil2 = fs.open(path, "w")
  41.         fil2.write("loadstring('"..newr.."')()")
  42.         fil2.close()
  43.         print("Encrypted "..sep(path, "/")[#sep(path, "/")])
  44.     else
  45.         print("File does not exist")
  46.     end
  47. end
  48.  
  49. function decrypt(path)
  50.     if fs.exists(path) and not fs.isDir(path) then
  51.         local fil = fs.open(path, "r")
  52.         local nr = fil.readAll()
  53.         fil.close()
  54.         local newf = ""
  55.         local newr = string.sub(nr, 13)
  56.         newr = string.sub(newr, 1, #newr - 4)
  57.         local fst = sep(newr, "\\")
  58.         for i,v in pairs(fst) do
  59.             newf = newf..string.char(tonumber(v))
  60.         end
  61.         fs.delete(path)
  62.         local fil2 = fs.open(path, "w")
  63.         fil2.write(newf)
  64.         fil2.close()
  65.         print("Decrypted "..sep(path, "/")[#sep(path, "/")])
  66.     end
  67. end
  68.  
  69. if #tArgs < 2 then
  70.     print("Usage: encrypt <e/d> <path>")
  71.     return
  72. end
  73.  
  74. if string.lower(tArgs[1]) == "e" then
  75.     encrypt(tArgs[2])
  76. elseif string.lower(tArgs[1]) == "d" then
  77.     decrypt(tArgs[2])
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement