Quick actions

cmd+k|ctrl+k

Navigation

Languages

LuaObfuscator

Snippet info

Language

Lua

Visibility

public

Author

randomizedcode18

Created

2025-06-05T12:17:17.488957Z

Updated

2025-06-05T12:17:17.488957Z

-- Obfuscator by luauruler26

local function obfuscateLua(scriptText)
	local function randomName(length)
		local chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
		local name = ""
		for i = 1, length do
			local rand = math.random(1, #chars)
			name = name .. chars:sub(rand, rand)
		end
		return name
	end

	local usedNames = {}
	local function getUniqueName()
		local name
		repeat
			name = "_" .. randomName(8)
		until not usedNames[name]
		usedNames[name] = true
		return name
	end

	-- Ganti variabel lokal
	local varMap = {}
	scriptText = scriptText:gsub("local%s+(%w+)", function(var)
		local newName = getUniqueName()
		varMap[var] = newName
		return "local " .. newName
	end)

	-- Ganti semua penggunaan variabel
	for old, new in pairs(varMap) do
		scriptText = scriptText:gsub("([^%w_])" .. old .. "([^%w_])", "%1" .. new .. "%2")
	end

	-- Encode semua string literal
	scriptText = scriptText:gsub("\"(.-)\"", function(str)
		local encoded = {}
		for i = 1, #str do
			table.insert(encoded, "string.char(" .. str:byte(i) .. ")")
		end
		return table.concat(encoded, " .. ")
	end)

	-- Hapus komentar
	scriptText = scriptText:gsub("%-%-.-\n", "")
	scriptText = scriptText:gsub("%-%-%[%[.-%]%]", "")

	-- Minify (hapus whitespace berlebihan)
	scriptText = scriptText:gsub("\n", ""):gsub("\t", ""):gsub(" +", " ")

	return scriptText
end

local myScript = [[
-- ini komentar
local hello = "Halo Dunia!"
print(hello)
]]

local obfuscated = obfuscateLua(myScript)
print(obfuscated)
INFO