picoctf/reverse engineering/SafeOpenerJAVA/SafeOpener.java
<gh_stars>0import 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 < 9999999999999999999999999999) {
            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 literally unlimited attempts left, :) - iUseYahoo");
                i++;
                continue;
            }
            break;
        }
    }
    
    public static boolean openSafe(String password) {
        // This looks like base64 to me..
        // Lets decode it in https://www.base64decode.org/ and see if it works
        // output: pl3as3_l3t_m3_1nt0_th3_saf3
        // hmm lets format it to the ctf: picoCTF{pl3as3_l3t_m3_1nt0_th3_saf3}
        // Wow, It works when you try to submit it, we found the flag.
        String encodedkey = "cGwzYXMzX2wzdF9tM18xbnQwX3RoM19zYWYz";
        
        if (password.equals(encodedkey)) {
            System.out.println("Sesame open");
            return true;
        }
        else {
            System.out.println("Password is incorrect\n");
            return false;
        }
    }
}
