import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.io.BufferedReader;
import java.util.Base64;
public class Main {
    public static void main(String[] args) throws Exception {
        String encoded_text = "uS0D11dq3RM9QimRWfXcewwQdoxYwrZRNUGT205pDfQ=";
        try(BufferedReader br = new BufferedReader(new java.io.FileReader("src/rockyouAES_Keys.txt"))) {
            String passphrase;
            while((passphrase = br.readLine())!= null) {
                System.out.println("Trying: " + passphrase);
                try {
                    String output = decrypt(encoded_text, passphrase);
                    if(output.startsWith("INS{")) {
                        System.out.println("Flag: " + output);
                        break;
                    }
                } catch (Exception e) {
                    continue;
                }
            }
        }
    }

    private static String decrypt(String str2, String str3) throws Exception {
        SecretKeySpec secretKeySpec = new SecretKeySpec(str3.getBytes(), "AES");
        byte[] decode = Base64.getDecoder().decode(str2);
        Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
        cipher.init(2, secretKeySpec);
        for (int i = 0; i < 313370; i++) {
            decode = cipher.doFinal(decode);
        }
        Cipher cipher2 = Cipher.getInstance("AES/ECB/PKCS5Padding");
        cipher2.init(2, secretKeySpec);
        return new String(cipher2.doFinal(decode), "UTF-8");
    }
}