Advertisement
Guest User

compress

a guest
May 22nd, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.02 KB | None | 0 0
  1. local function Decompile(CompiledTbl)
  2.   local Str = ''
  3.   for k, v in pairs(CompiledTbl) do
  4.     Str = Str .. string.char(v)
  5.   end
  6.   return Str
  7. end
  8.  
  9. local function Compile(Str)
  10.   local Compiled = {string.byte(Str,1,#tostring(Str))}
  11.   return Compiled, table.concat(Compiled, ',')
  12. end
  13.  
  14. local Compiled, Concat = Compile('{HelloWorld = "mikkel809h"}')
  15. print(Concat)
  16. local Decompiled = Decompile(Compiled)
  17. print(Decompiled)
  18.  
  19.  
  20.  
  21. --[[
  22. local Path = '/'
  23. local Contents = {}
  24.  
  25. local function GetDir(Path)
  26.   if Path:find('rom/') then
  27.   else
  28.     local List = fs.list(Path or '/')
  29.     for k, v in pairs(List) do
  30.  
  31.       local CurrentPath = Path..fs.getName(
  32.         fs.combine(
  33.           Path,
  34.           v
  35.         )
  36.       )
  37.       if fs.isDir(CurrentPath) then
  38.         CurrentPath = CurrentPath .. '/'
  39.       end
  40.       print(tostring(CurrentPath))
  41.       if fs.isDir(CurrentPath) then
  42.         GetDir(CurrentPath)
  43.       else
  44.         local File = fs.open(CurrentPath, 'r')
  45.         if File then
  46.           local Data = File.readAll()
  47.           -- Compile data --
  48.           Data = {string.byte(Data,1,#tostring(Data))}
  49.           --print(table.concat(Data, ', '))
  50.           --os.pullEvent()
  51.           File.close()
  52.           Contents[CurrentPath] = Data
  53.           os.queueEvent('Ping')
  54.           os.pullEvent('Ping')
  55.         end
  56.       end
  57.     end
  58.   end
  59. end
  60.  
  61.  
  62. GetDir(Path)
  63.  
  64. --print('Waiting for input...')
  65. --os.pullEvent('key')
  66. --term.clear()
  67. --term.setCursorPos(1,1)
  68. Compiled = fs.open('Compiled', 'w')
  69. Compiled.writeLine(textutils.serialize(Contents))
  70. Compiled.close()
  71. --print('Decompiling...')
  72. --local Decompiled = {}
  73. --for k, v in pairs(Contents) do
  74. --  Decompiled[k] = ''
  75.   for i, j in pairs(v) do
  76.     print(i .. ' -> ' .. tostring(string.char(j)))
  77.     Decompiled[k] = Decompiled[k]..string.char(j)
  78.   end
  79. end
  80. if not fs.isDir('Decompiled') then
  81.   fs.makeDir('Decompiled')
  82. end
  83. for k, v in pairs(Decompiled) do
  84.   Decompiled = fs.open('Decompiled/'..k, 'w')
  85.   Decompiled.write(v)
  86.   Decompiled.close()
  87. end
  88. --]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement