Hi folks, I doubt you guys are looking for 'encryption', but instead, are looking for 'obfuscation'.
To know the difference between the two, let me explain what they mean:
- Encryption: "the process of converting information or data into a code, especially to prevent unauthorized access."
- Obfuscation: "the action of making something obscure, unclear, or unintelligible."
The problem is that Encryption is what you want as it's the best at 'securing' your code from unauthorized access, however the receiver of your code will most likely 'decrypt' the code to use it, making it completely obsolete.
The solution is Obfuscation as the Lua script will be transformed into something that still has the same functionality, however it has been "transformed' in the worst possible way so that humans will have a very hard time understanding what it does. Good obfuscation means it is simply to hard/difficult to understand what the script does for a human.
So where do you get obfuscation? you can use free online tools such as https://luaobfuscator.com/, I have no experience with other tools as most of them are pay to use.
Example use of LuaObfuscator.com:
-- sample snippet to calculate prime numbers:
do
function sieve_of_eratosthenes(n)
local is_prime = { }
for i = 1, n do
is_prime[i] = 1 ~= i
end
for i = 2, math.floor(math.sqrt(n)) do
if is_prime[i] then
for j = i* i, n, i do
is_prime[j] = false
end
end
end
return is_prime
end
local primes = sieve_of_eratosthenes(420)
for key, value in pairs(primes) do
if (value) then
print("Prime found: " .. key)
end
end
end
Obfuscated output (CFFv1, Strings, Minifiy )
local v0 = string.char;
local v1 = string.byte;
local v2 = string.sub;
local v3 = bit32 or bit;
local v4 = v3.bxor or v3.bxor;
local v5 = table.concat;
local v6 = table.insert;
local function v7(v8, v9)
local v12 = {};
for i = 1, #v8 do
v6(v12, v0(v4(v1(v2(v8, i, i + 1)), v1(v2(v9, 1 + ((i - 1) % #v9), 1 + ((i - 1) % #v9) + 1))) % 256));
end
return v5(v12);
end
do
local v10 = 0;
local v11;
while true do
if (v10 == 1) then
for key, value in pairs(v11) do
if value then
print(v7("\3\43\133\37\54\121\138\39\38\55\136\114\115", "\83\89\236\72") .. key);
end
end
break;
end
if (v10 == 0) then
function sieve_of_eratosthenes(v13)
local v14 = 0;
local v15;
while true do
if (v14 == 0) then
v15 = {};
for i = 1, v13 do
v15[i] = 1 ~= i;
end
v14 = 1;
end
if (v14 == 1) then
for i = 2, math[v7("\205\90\58\188\217", "\171\54\85\211")](math[v7("\7\152\255\8", "\116\233\141\124\175\201\74\192")](v13)) do
if v15[i] then
for j = i * i, v13, i do
v15[j] = false;
end
end
end
return v15;
end
end
end
v11 = sieve_of_eratosthenes(420);
v10 = 1;
end
end
end