Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[Obfuscation] How do I Deobfuscate the Obfuscated code correctly?

local function Obfuscate(code)
	local oCode = ''
	for i = 1,code:len() do
		oCode = oCode .. string.byte(string.sub(code,i,i)) .. ','
	end
	oCode = string.sub(oCode,1,oCode:len() - 1)
	return oCode
end

local function Deobfuscate(code)
	local dCode = ''
	for i = 1,code:len(),2 do
		--if string.sub(code,i,i + 1) ~= ',' then
			dCode = dCode .. string.char(tonumber(string.sub(code,i,i + 1)))
			print(dCode)
		--else
			
		--end
	end
	return dCode
end

local Code = Obfuscate('Print')
print(Code)
local oCode = Deobfuscate(Code)
print(oCode)

Errors:

14: bad argument #1 to 'char' (number expected, got nil)

1 answer

✓ Accepted answer

Obfuscate doesn't result in a string of alternating commas and digits like you seem to be assuming it does.

It doesn't form any nice pattern, and since Lua doesn't provide a split method, you won't want to implement it the way you are.


One option is to use the :gmatch string method as an iterator:

for numerals in code:gmatch("%d+") do
	dCode = dCode .. string.char(tonumber(numerals))
end



While it's not related directly to your question, I would like to point out that doing obfuscation in this form is futile. Since everything has to be piped through some function like Deobfuscate to run it, whoever wants to discover the original just has to change loadstring (or whatever other evaluation) to print.

Successful code obfuscation requires that the code runs as it is, without having to do some post-processing on it.

E.g., consider this:

function g(a, b, u, v)
	return b > 0 and u(b - 1, a * b, u, v) or a;
end

function f(x, y, u, v)
	return x == 0 and y or v(y * x,x - 1, u, v)
end

function e(n)
	return f(n, (n + 1) / (n + 1), f, g);
end

any idea what e does? Any idea how it works?

4 comments

0

How e works: It returns double n multiplied by the recursive reverse of n-1, down to 1. Ex: e(5) > 1*1 = 1| * 2 =2| *3 = 6|*4=24|*5=120|BREAK; I was able to figure this out by noticing that e made f call g, subtracting from the original value and multiplying by the previous value, and g did the same with f, and the process looped repetitively until either the modified original value was less than

0

[Continued] --less than-- 0, or a stack overflow occurred from the functions calling each other too many times in a time period. The function e would then return the incremented value.

0

Thx I'm sorry I didn't reply as soon as possible. I actually quit roblox because of this problem and went to Unity 3D learning C#.

0

Lua now has a split method by the way

This discussion is preserved as it was. New answers, comments, and votes are closed.