This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Dust286's profile picture

Function obfuscation / code protection

Started by Dust286, 07 July 2015 - 09:18 PM
Dust286 #1
Posted 07 July 2015 - 11:18 PM
Exists a way to obfuscate or protect a function or a part of code? I've read about bytecode and base64 encode, but I don't understand some technical words in english.

If this is possible in CC, please leave an example or how to make it

My english is so bad, sorry
KingofGamesYami #2
Posted 08 July 2015 - 02:44 AM
Well, string.dump can do this.

lua-users wiki said:
string.dump(function)

Returns a binary representation of the given function, so that a later loadstring on that string returns a copy of the function. Function must be a Lua function without upvalues.

http://lua-users.org/wiki/StringLibraryTutorial

Example:

local function helloWorld()
  print( "Hello World" )
end

local bin = string.dump( helloWorld )
local file = fs.open( shell.getRunningProgram(), "w" )
file.write( bin )
file.close()
print( "Running file" )
sleep( 0.1 )
shell.run( shell.getRunningProgram() )

Base64 is meant for strings, and it's pretty easy to find an encoder/decoder for lua online.
クデル #3
Posted 08 July 2015 - 07:10 AM
Sorry kind of an odd question, is there a way to dump a string rather than a function?
Bomb Bloke #4
Posted 08 July 2015 - 08:42 AM
Bear in mind that obfuscated code is off-limits on these forums.

Sorry kind of an odd question, is there a way to dump a string rather than a function?

Given that a dumped function is a string, why would you possibly want to attempt to dump a string? What result are you expecting?
MKlegoman357 #5
Posted 08 July 2015 - 11:26 AM
You can turn your code into bytecode but that doesn't actually hide anything. There are Lua bytecode to Lua code decoders out there so it wouldn't be hard to decode the obfuscated code. What's the main reason you want your code to be hidden?
クデル #6
Posted 09 July 2015 - 06:51 AM
Bear in mind that obfuscated code is off-limits on these forums.

Sorry kind of an odd question, is there a way to dump a string rather than a function?

Given that a dumped function is a string, why would you possibly want to attempt to dump a string? What result are you expecting?

Perhaps I wanted to "obfuscate" a message that was travelling between modems or something alike?
Anavrins #7
Posted 09 July 2015 - 07:19 AM
Perhaps I wanted to "obfuscate" a message that was travelling between modems or something alike?
In that case I would use encryption, you can't send a string.dump string over modem and expect it to run at the other end.