> 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/powershelly.md).

# powershelly

We are given:

* `rev_PS.ps` (PowerShell script)
* `output.txt`

Goal: find the correct `input.txt` → get flag

***

### Step 1: Understand basic checks

Script checks:

* File must be **9245 bytes**
* Max **5 lines**
* Only allowed characters:
  * `0`, `1`, space, newline

So input is basically **binary data (0/1)**

***

### Step 2: Structure of input

Each line:

* Split by spaces
* Each block = **6 characters** (like `101010`)
* Total columns = **264**

Example:

```id="a1"
101010 111000 000111 ...
```

***

### Step 3: Column logic (important)

Script does something tricky:

* Instead of reading rows → it builds **columns**
* Each column becomes:

```id="a2"
[column0] = [block_from_line1, block_from_line2, ...]
```

***

### Step 4: Seeds + Random

Script generates:

* `seeds` → based on index
* `randoms` → using a formula

Then for each column:

```id="a3"
result = fun ^ previous_result ^ random
```

Means:

* Everything depends on previous value
* One mistake → everything breaks

***

### Step 5: Hard part (skipped brute force)

We reverse logic using Python script:

* Recreate same operations
* Try to recover correct input

***

### Step 6: Final observation

After solving:

* Each column only had **2 possible patterns**
* That means → it's basically **binary (0 and 1)**

So we convert patterns → `0` and `1`

***

### Step 7: Decode binary

Binary → text → flag

***

### Flag

```id="a4"
picoCTF{2018highw@y_2_pow3r$hel!}
``
```


---

# 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/powershelly.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.
