MathsWorld
All Exhibits

Safe Cracking

Find the code for the 2-digit safe.
How many possibilities are there for a 2-digit code? What about a 3-digit code or a 4-digit code?
The 2-digit safe accepts the last two digits typed on the keypad. What would be the most efficient way to check all the possibilities?

The number of possibilities increase as the codes get longer making brute force more difficult. Our keypad uses four numbers, meaning there are four choices for each step of the code. To work out the number of possibilities we multiply our choices together.

So, for the 1-digit code there are 4 possibilities. For a 2-digit code there are 16 = 4 × 4 possibilities. And, for the 3-digit code, there are 64 = 4 × 4 × 4 possibilities.

For a 4-digit code, there are 256 = 4 × 4 × 4 × 4 possibilities. It would take a long time to check them all! Fortunately, our safe just uses even numbers, so how many possibilities does it have?

The following sequence contains all the possible 2-digits codes and is the most efficient way to check all the possibilities. 11213142232433441

This is called a de Bruijn sequence and is 17 digits long. Similar sequences can be found to crack the 3-digit code and 4-digit code.