Creating combination cracking code | For Beginner Scripters [FUN]

Introduction, Usage & Content

Hello,

This is more of something I wanted to share than a tutorial, some may already know the logic but this something I want to show the beginner scripters and make a tutorial to make combination cracking code. It’s actually pretty fun once you get involved into alphabets and numbers but for this tutorial, I will only be doing numbers.


DISCLAIMER: THIS DOES NOT SUPPORT ANY KIND OF “PASSWORD CRACKING.” IT IS NOT CODE EFFICIENT EITHER, THIS REQUIRES AN ENDLESS AMOUNT OF CODE OUTPUT SPACE [FOR SOME COMBINATIONS].

  • It is highly unlikely that this code might crack every number as the program keeps guessing and guessing till it gets the correct match (that’s pretty much what all code crackers do unless you know something about the code). I did try it on online lua compilers but had limited code output, I believe roblox also has a limited code output.

  • Why am I posting this if you require a lot of code output? When I tested the code with some preset numbers, it did work and I wanted to make a tutorial to show how you can code different types of computer algorithms to work wonders for you.

If you’re an advanced scripter, you might find it boring.

Tutorial

Okay so, first create two tables. One table called numbers that have the numbers from 0-9 and another table called trash which is empty. The trash table will be used to increase code efficiency and not test the same values again if in case they do repeat (that possibility is 1 in 10,000!)

local numbers = {0,1,2,3,4,5,6,7,8,9}
local trash = {}

Now that we made the tables, let’s go define a function that will do all the logic for us. So we’re going to select random numbers from the numbers table and check if it is repeated, if it is repeated, we’re going to select another set of random indexes. After that we will concatenate the values from the given indexes.

local numbers = {0,1,2,3,4,5,6,7,8,9}
local trash = {}

function generate()
   local index = math.random(1, #numbers)
   local index2 = math.random(1, #numbers)
   local index3 = math.random(1, #numbers)
   local index4 = math.random(1, #numbers)
   -- Seems rather disastrous, I didn't think of any other way :shrug:
   local combination = numbers[index]..numbers[index2]..numbers[index3]..numbers[index4]
    -- We're going to loop through the trash table to avoid the same value, although you really don't need to do this. The possibility of getting the same number again is 1 out of 10,000 (if you're using 4 digits). 
   for i, v in pairs(trash) do
       if tostring(v) == tostring(combination) then
       end
   end
end

We just created our combination!
Now we do redo the same thing for the trash folder. And you will see me use local index again but it does not matter since we’re doing this through a local scope.

local numbers = {0,1,2,3,4,5,6,7,8,9}
local trash = {}

function generate()
   local index = math.random(1, #numbers)
   local index2 = math.random(1, #numbers)
   local index3 = math.random(1, #numbers)
   local index4 = math.random(1, #numbers)
   -- Seems rather disastrous, I didn't think of any other way :shrug:
   local combination = numbers[index]..numbers[index2]..numbers[index3]..numbers[index4]
    -- We're going to loop through the trash table to avoid the same value, although you really don't need to do this. The possibility of getting the same number again is 1 out of 10,000 (if you're dealing with 4 digits). 
   for i, v in pairs(trash) do
       if tostring(v) == tostring(combination) then
          local index = math.random(1, #numbers)
          local index2 = math.random(1, #numbers)
          local index3 = math.random(1, #numbers)
          local index4 = math.random(1, #numbers)
         -- What we're also going to do is add the combination to the trash folder to define values we do not want which the one we used.
          table.insert(trash, combination) -- Just skip the second parameter. 
          return combination
       end
   end
end

Since we set the code to return a new number if the combination already existed, now we need to make the one where it just returns the numbers. If you’re thinking about an else statement for the if tostring(v)..., then that’s not really efficient since by returning the combination, the function won’t execute any code after. We can just leave that there and continue after.

local numbers = {0,1,2,3,4,5,6,7,8,9}
local trash = {}

function generate()
   local index = math.random(1, #numbers)
   local index2 = math.random(1, #numbers)
   local index3 = math.random(1, #numbers)
   local index4 = math.random(1, #numbers)
   -- Seems rather disastrous, I didn't think of any other way :shrug:
   local combination = numbers[index]..numbers[index2]..numbers[index3]..numbers[index4]
    -- We're going to loop through the trash table to avoid the same value, although you really don't need to do this. The possibility of getting the same number again is 1 out of 10,000 (if you're dealing with 4 digits). 
   for i, v in pairs(trash) do
       if tostring(v) == tostring(combination) then
          local index = math.random(1, #numbers)
          local index2 = math.random(1, #numbers)
          local index3 = math.random(1, #numbers)
          local index4 = math.random(1, #numbers)
         -- What we're also going to do is add the combination to the trash folder to define values we do not want which the one we used.
          table.insert(trash, combination) -- Just skip the second parameter. 
          return combination
       end
   end
   table.insert(trash, combination)
   -- We are inserting the combination so that we don't use it again.
   return combination
end

With that, we finished our function.

Now all there is to do is the process to keep guessing. We can do that through a while loop, we keep guessing and break the loop once we get our value. You can add this to the end of your code-

local key

while wait(.1) do
	key = generate()
	if tostring(key) == '5034' then
		print('Cracked!')
		break
	end
	print(key)
end

And now we’re done!

You could define the key inside the loop but I just initialized it outside to approach it through a global scope just in case we may need it for future encounters.

Tips & Pointers

  • You might be tempted to do local key = generate() instead of initializing it at the start but doing so will get you nowhere sometimes. Remember that we do not want to use used combinations and we’re filtering out used ones before even they can reach the loop. So if your combination got cracked in the first try, before it entered the loop, you’re never going to get the number back since it’s in the trash table.

  • The possibility of cracking a 4 digit code is 1 in 10,000. If you create 1 combination per millisecond, you can get the combination in 1000 seconds. That’s nearly 17 minutes if I round it to the nearest whole number.

  • You might be lucky and get the combination before your computer runs out of memory!

Finally

If you have any questions or problems, reply to this topic and ask them and I will answer them whenever I’m free.

Thank you for reading!

3 Likes

Id recommend avoiding using math.random as its not true random, so it will often return the same results and have patterns. An approach that might be able to have less chance of running into the same value twice would be using an indexing method (e.g. 1, 2, 3, 4, 5 etc) with a SHA256 hashing that value each time. This has a much lower chances of having 2 numbers after each other be the same. The downside of this method however is that it generates as its name suggests a 256 bit value which Roblox lua cannot handle. So you will need to find a way to funnel it into the guessing range. a very rough example would be taking 4 numbers from the start and 4 numbers from the last. and adding them together.

This method would be a lottt less efficient, however would have less chance of there being 2 values being the same. (SHA has butterfly effect built into it, to ensure that there are very big differences between values) It also could allow for some kind of caching to speed up results as well.

I also recommend to stop the loop from timing out do something like this:

local TimeoutIndex = 1
local Running = true
while Running do
   -- perform guess..
   TimeOutIndex += 1
   if TimeOutIndex%1000 then
      task.wait()
   end
end

Adjust the 1000 to whatever value based on how performance intensive it is. otherwise it may timeout. This will run through results at blazing fast speed!

2 Likes

Thanks for the tip! I will use this next time but I wanted this tutorial to be easier just to show the logic behind combination cracking.

If you are making a program that literally cracks a 4 digit code, couldn’t you in theory just do it by adding 1 through 9,999?

local currentCount = 0 
local password = 5034

while currentCount < 10000 and currentCount ~= password do 
	currentCount += 1
end

print(currentCount, "is the password")
2 Likes

very smart. Much efficient, this is actually smart

However if your trying a letter password this won’t really work

You could do that but most combinations/passwords include alphabetical or special character types. The code you presented could also be achieved through a for i = and go in an ascending order through numbers. It is much more efficient and gets the job done a lot more quicker but I posted this tutorial so people would build better code based on the idea of testing every possible outcome. So this was just an example to build a more complex combination cracker.