Jump to content




Text and numbers to binary


  • You cannot reply to this topic
3 replies to this topic

#1 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

Posted 31 March 2013 - 07: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()


#2 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

Posted 31 March 2013 - 07: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


#3 JokerRH

  • Members
  • 147 posts

Posted 31 March 2013 - 01:48 PM

So this is a working program, isn't it?
If yes then you should probably move it to programs...:P

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 31 March 2013 - 02: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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users