Hi there, I’ve made a module that generates “encrypted” IDs for the lobby.
Overview:
local module = {}
function module.CreateLobbyID(IDAmount)
local random = Random.new()
local letters = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}
local symbols = {'!','@','#','$','%','^','&','*','(',')','.','?','/','`','~', '_', '-', '=', '+', '{', '}', '[', ']', ';', ':', '"', '|'}
local IDs = {}
local function returnRandomLetter()
return letters[random:NextInteger(1,#letters)]
end
local function returnRandomSymbol()
return symbols[random:NextInteger(1,#symbols)]
end
for IDSent = IDAmount, 1, -1 do
local MinInt = 100000
local MaxInt = 999999
local GeneratedSeed = math.random(MinInt, MaxInt)
-- Encryption
local ReversedSeed = string.reverse(tostring(GeneratedSeed))
local CalculatedSeed = tostring(tonumber(ReversedSeed) - GeneratedSeed)
for i = 1, math.random(1,math.pow(6, 3)) do
local RandomLetter = returnRandomLetter()
local RandomSymbol = returnRandomSymbol()
local Result1 = string.sub(CalculatedSeed, math.random(1,6), math.random(-1,6)) .. RandomLetter .. string.sub(CalculatedSeed, math.random(1,6))
local Result2 = string.sub(Result1, math.random(1,6), math.random(-1,6)) .. RandomSymbol .. string.sub(Result1, math.random(1,6))
NewSeed = string.reverse(Result2 .. Result1)
end
table.insert(IDs, NewSeed)
end
for i, id in pairs(IDs) do
print(id)
end
end
return module
I’m not satisfied about how I “encrypted” the IDs, I think it would just not work to prevent against hackers joining matches, but it gets the job done.
Explanation on how it works:
First, it generates a seed that’s random from 100000 to 999999, then make a variable that turns the seed into a string in order to reverse the seed then turn it back to a number to do a calculation like this:
RevSeed - GenSeed
Then turn the calculated seed into a string to begin the process of “encryption”.
For every time until 6^3 (216), Replace 1 to 6 numbers from the calculated seed with a random letter, then do it again except with a random symbol instead.
Then reverse the “encrypted” seed again and place it inside of the IDs table.
Yes, that sounds confusing. So here’s the summary about how it works:
- Get a number between 100000 and 999999.
- Reverse the number and Subtract that number from the original.
- Replace a random amount of 1 to 6 numbers with a random letter, then do the same thing except with a random symbol, 1 to 213 times.
- Reverse it again and place it inside of the table named “IDs”.
Conclusion
I think this script needs an overhaul on the “encryption” because it may not be secure, but my head feels light rn so I can’t think of anything other than this abomination.