Tags: reverse
Rating:
Safe Openner is the realy simple task that check your Java skills. But if you don't know how Java work it is very easy to understand what happen in the programm.
Code:
```
import java.io.*;
import java.util.*;
public class SafeOpener {
public static void main(String args[]) throws IOException {
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
Base64.Encoder encoder = Base64.getEncoder();
String encodedkey = "";
String key = "";
int i = 0;
boolean isOpen;
while (i < 3) {
System.out.print("Enter password for the safe: ");
key = keyboard.readLine();
encodedkey = encoder.encodeToString(key.getBytes());
System.out.println(encodedkey);
isOpen = openSafe(encodedkey);
if (!isOpen) {
System.out.println("You have " + (2 - i) + " attempt(s) left");
i++;
continue;
}
break;
}
}
public static boolean openSafe(String password) {
String encodedkey = "cGwzYXMzX2wzdF9tM18xbnQwX3RoM19zYWYz";
if (password.equals(encodedkey)) {
System.out.println("Sesame open");
return true;
}
else {
System.out.println("Password is incorrect\n");
return false;
}
}
}
```
It give us three attempt to guess the flag. And we see comparision with "cGwzYXMzX2wzdF9tM18xbnQwX3RoM19zYWYz" string. Our input is transmissed to bytes and to base64 in 17-18 strings. Then our encoded flag give to openSafe function, it open flag file if our encoded flag is "cGwzYXMzX2wzdF9tM18xbnQwX3RoM19zYWYz". Okay, try to write reverse programm:
```
import java.io.*;
import java.util.*;
public class Programm {
public static void main(String args[]) {
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
String encodedkey = "cGwzYXMzX2wzdF9tM18xbnQwX3RoM19zYWYz";
String key = "";
String byte_key = "";
byte[] decodedBytes = Base64.getDecoder().decode(encodedkey);
key = new String(decodedBytes);
System.out.println(key);
}
}
```
The programm do opposite actions and return us our flag. Check it with first Java programm and get our 100 points.