451 posts
Location
The left part of this post
Posted 31 March 2013 - 08:27 AM
Its a way to convert all a lua program to a binary representation and then recover that program
ex:
args = {...}
file = fs.open(args[1], "r")
a = tobynary(file.readAll())
b = frombinary(a)
file = fs.open("output", "w")
file.write(B)/>
file.close()
451 posts
Location
The left part of this post
Posted 31 March 2013 - 08:35 AM
I founded, if somebody is interested this is the code;
function toBase(str, base) --Encodes @str in @base
if not base then return nil end
str = tostring(str)
local res = ""
for i = 1, str:len() do
if i == 1 then
res = basen(str:byte(i), base)
else
res = res..":"..basen(str:byte(i), base)
end
end
return res
end
function fromBase(str, base) --Decodes @str from @base
if not base then return nil end
str = tostring(str)
local bytes = seperate(str, ":")
local res = ""
for i = 1, #bytes do
res = res..(string.char(basen(tonumber(bytes[i], base), 10)))
end
return res
end
function toBinary(str) --Encodes @str in binary
if not str then return nil end
str = tostring(str)
return toBase(str, 2)
end
function fromBinary(str) --Decodes @str from binary
if not str then return nil end
str = tostring(str)
return fromBase(str, 2)
en
148 posts
Posted 31 March 2013 - 02:48 PM
So this is a working program, isn't it?
If yes then you should probably move it to programs…:P/>
7508 posts
Location
Australia
Posted 31 March 2013 - 03:18 PM
you know there is a way to read and write files in binary mode. when opening the file use 'rb' or 'wb' and it will be open in binary mode.