Stranger Code Challenge

Welcome to our latest programming challenge! This time, we’re diving into the world of Stranger Things and the challenge is based on a piece of code seen in the second series of Stranger Things (Episode 8) where, following a total blackout, some of the characters of the series are trapped inside Hawkins Lab, a secretive governmental laboratory. In order to hack into the central computer system, Bob, one of the beloved characters, has to write some code in BASIC to find the 4-digit passcode needed to access Hawkins Lab’s door access system. The code seen on the screen is written in BASIC, a programming languages used in the 1980s’. The aim of this programming challenge will be to rewrite this code in Python.

The code written by Bob is used to implement a brute force attack to test all possible combinations of 4-digit codes from 0000 to 9999 until the right passcode is found. Here is the code seen on Bob’s screen:

10 DIM FourDigitPassword INTEGER
20 FOR i = 0 TO 9
30     FOR j = 0 TO 9
40          FOR k = 0 TO 9
50                FOR l = 0 TO 9
60                      FourDigitPassword = getFourDigits (i,j,k,l)
70                      IF checkPasswordMatch(FourDigitPassword) = TRUE THEN
80                              GOTO 140
90                      END
100                NEXT l
110          NEXT k
120     NEXT j
130 NEXT i
140 PRINT FourDigitPassword
150 END

The code provided shows two functions being called: getFourDigit(i, j, k, l) on line 60 and checkPasswordMatch(FourDigitPassword) on line 70. We will assume that these

  • getFourDigit(i, j, k, l): This function takes four digits as parameters and returns a 4-digit integer. For example, if the inputs are 3, 4, 5, 6, the function should return 3456.
  • checkPasswordMatch(FourDigitPassword): This function takes a 4-digit integer and returns True if the parameter passed is the correct password, otherwise it returns False.

We will assume these two functions are part of the Hawkins Lab central computer system and we will use an import statement in Python to import and use these. However it will be part of the programming challenge to complete the code for these two functions.

Your Task

You will need to complete this task in three steps as follows:

Go into the hawkins_lab.py file in the Python IDE provided below and complete the code for the getFourDigit() function. The aim of this function is to take four integer as parameters (e.g. 3, 4, 5 and 6) and return a 4-digit integer (e.g. 3456)

Within the hawkins_lab.py file, complete the code for the checkPasswordMatch() function. The aim of this function is to take a 4-digit integer (e.g. 3456) as a parameter and compare it with the actual passcode to give access to the door access system. The correct passcode will be hardcoded within this function as 1984. If the password passed as a parameter is a match (=1984) then the function will return True, otherwise it will return False.

In the main.py file, rewrite the main code in Python from Bob’s code provided in BASIC. This is the code used to implement the Brute Force Attack to test all 4-digit passcodes from 0000 to 9999 using 4 nested loops and the two functions from hawkins-lab.py.

Python Code

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 3

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!