Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local updateCode = Instance.new("Event") -- CONNECT GETTING A NEW BOOK OR EXITING THE LIBRARY TO THIS
- local function getKnownCode() -- updateCode.Event:Connect(function() bruteForceCode(getKnownCode()) end)
- --[[
- 1) Get paper shapes
- 2) Get known shapes from Gui
- 3) Translate that information into a string where unknown digits are marked with an underscore
- 4) Return that string
- --]]
- end
- ----
- local digit = {}
- function digit.new(num)
- local digitClass = {}
- --Variables
- digitClass.Val = num or 0
- --Methods
- if not num then
- function digitClass:Iterate()
- self.Val = (self.Val+1) % 10
- return self.Val, (self.Val == 0)
- end
- else
- function digitClass:Iterate()
- return self.Val, true
- end
- end
- return digitClass
- end
- local function getPossibleCodes(known, attempts)
- if #known ~= 5 then error("code '"..known.."' is invalid: code should be 5 digits") end
- ---
- local digits = {} -- digits
- for d = 1, #known do
- local c = known:sub(d,d)
- if c == "_" then
- table.insert(digits, digit.new())
- else
- table.insert(digits, digit.new(tonumber(c)))
- end
- end
- local codes = {}
- for a = 1, attempts do
- local code = ""
- local iterateNext = true
- for i, d in pairs(digits) do
- if iterateNext then
- local val, next = d:Iterate()
- iterateNext = next
- code = code..tostring(val)
- else
- local val = d.Val
- code = code..tostring(val)
- end
- end
- table.insert(codes, code)
- end
- return codes
- end
- local function bruteForceCode(known)
- local unknown = 0
- for i = 0, #known do
- if known:sub(i,i) == "_" then
- unknown = unknown+1
- end
- end
- local exitLoop = false
- updateCode.Event:Connect(function()
- exitLoop = true
- end)
- for _, code in pairs(getPossibleCodes(known, 10^unknown)) do
- game.ReplicatedStorage.EntityInfo.PL:FireServer(code)
- task.wait()
- ---
- if exitLoop then break end
- end
- end
- updateCode.Event:Connect(function()
- bruteForceCode(getKnownCode())
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement