Chapter 20. The final phase, we create a door unlocking tool
We have everything ready for the escape. As I’ve already told you, I’ll be in charge of opening the final door. Right next to the exit there’s a table with a computer from which you can access the entire system and, by the way, open the main door. Normally, five security keys are used and without them it’s impossible to open it. Needless to say, with my current computer knowledge it would be impossible for me to hack it.
However, Bud and Pedro know the system perfectly. They have been working with it for years and have even programmed much of the code that controls the main security functions. They wanted to make things easier for me to ensure that we can get out without complications and quickly. To do this, they have created five programs that are hosted in five different classes. These classes are already hidden within the system, so my only task is to create a Main class and call the methods found in them.
It’s a humble task, but of vital importance. I’m not going to go in blindly; Bud has taken care to show me the five programs and explain what they’re for. Also, we’ve already practiced how I should call the methods, so it can be said that I know by heart what I have to do. I wouldn’t want to get nervous and go blank at the most critical moment.
To give you an idea, I’m going to show you the classes below and give you an explanation of what each one is for. Evidently, Bud has dedicated a lot of time to working on them and has checked many times that there is no error that could compromise our escape.
1. Key Class
I had told you that five keys are needed to open the door normally. We only have one; we got it when we accessed Vicente’s office. We’re lucky, as it’s the most important one; thanks to it, the remaining steps can be followed to, ultimately, completely disarm it. This class allows the system to check that the key we have is still active and valid. Therefore, this class represents a key and verifies if the key is valid.
public class Key {
private String key;
public Key(String key) {
this.key = key; // Correctly assign the parameter to the attribute
}
public boolean isValid() {
// Simple key verification
return "correctKey".equals(this.key);
}
}
2. AccessCode Class
This class represents an access code and verifies if the code is correct.
public class AccessCode {
private int code;
public AccessCode(int code) {
this.code = code;
}
public boolean isValid() {
// Simple access code verification (can be any logic)
return this.code == 1234;
}
}
3. Light Class
For the door to open, it is absolutely mandatory that the spotlight illuminating the door from the outside is on. This helps increase security and visibility in the area. However, we prefer darkness, so that the cameras don’t detect us. Therefore, we must make the system believe that the light is on. We will do this with the following method.
public class Light {
public void turnOn() {
// Simulate turning on the light System.out.println("The light is on.");
}
}
4. Alarm Class
When the door opens without authorization, an alarm sounds, and we don’t want that to happen. We must create a method that indicates that the alarm is activated, although we have already taken care of deactivating it previously.
public class Alarm {
public void enable() {
// Simulate that the alarm is active. System.out.println("The alarm is activated.");
}
}
5. Door Class
Finally, we want to fool the security system and indicate that the door is open. We will simply have to create a class that indicates that, indeed, the door is open. In this way, it really will be and, finally, we will be able to get out.
public class Door {
public void open() {
// Simulate opening the door System.out.println("The door is open.");
}
}
Main Class
In this class, we create the necessary objects and call their methods to open the door.
public class Main {
public static void main(String[] args) {
// Create objects
Key key = new Key("67898");
AccessCode accessCode = new AccessCode(787656);
Light light = new Light();
Alarm alarm = new Alarm();
Door door = new Door();
// Process to open the door
if (key.isValid() && accessCode.isValid()) {
// methods are called on the objects
light.turnOn();
alarm.enable();
door.open();
} else {
System.out.println("The key or access code is incorrect. The door cannot be opened.");
}
}
}
Basically, that’s all there is to it. Let’s hope that tonight everything goes well. It has taken us a lot of effort to get here, and it would be a big problem not to achieve our escape. Although it would be much worse if we were caught. If that happened, I would expect a long period of imprisonment, Rich would remain unpunished and justice would never be done.