> For the complete documentation index, see [llms.txt](https://alham-rizvi.gitbook.io/alhamrizvi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alham-rizvi.gitbook.io/alhamrizvi/picoctf-writeups/picoctf/reverse-engineering/fresh-java.md).

# Fresh Java

This challenge provided a compiled Java `.class` file. To start, I needed to convert the bytecode into readable source code. For that, I used a Java decompiler.

First, I downloaded the CFR decompiler and ran:

```bash
java -jar cfr.jar KeygenMe.class
```

This produced a readable Java source file. Another option is to use tools like JD-GUI or even `javap -c` for bytecode, but CFR gives clean output which is easier to understand.

After decompiling, I analyzed the `main` function. The program takes input from the user and checks if it is a valid key. It first verifies that the length of the input is 34 characters. Then it performs a series of checks using `string.charAt(index)` to compare each character at specific positions.

If any character does not match, the program prints “Invalid key” and exits. If all conditions are satisfied, it prints “Valid key”.

Instead of guessing the key, I reversed the logic by reading each condition and reconstructing the string. Every `charAt(index)` tells exactly what character must be at that position. By collecting all characters from index 0 to 33 and placing them in order, I rebuilt the full key.

After combining all characters, the final flag is: picoCTF{700l1ng\_r3qu1r3d\_738cac89}

This challenge shows that Java bytecode can be easily decompiled, and many times the flag is directly embedded in the validation logic, making it possible to recover it by simple static analysis.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://alham-rizvi.gitbook.io/alhamrizvi/picoctf-writeups/picoctf/reverse-engineering/fresh-java.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
