# Transformation

## Problem

> I wonder what this really is... enc `''.join([chr((ord(flag[i]) << 8) + ord(flag[i + 1])) for i in range(0, len(flag), 2)])`

* [enc](https://github.com/HHousen/PicoCTF-2021/blob/master/Reverse%20Engineering/Transformation/enc/README.md)

## Solution

1. `cat enc`: `灩捯䍔䙻ㄶ形楴獟楮獴㌴摟潦弸弲㘶㠴挲ぽ`
2. The python code in the challenge text is the program used to encode the original flag. It is the program that we need to reverse.
3. The program shifts the bits for every other letter of the flag left by 8 bits (1 byte). Then, it adds the next latter of the flag to the shifted value. In other words, each letter is represented as a byte and they are joined together in pairs of two.
4. We can reverse this (see [script.py](https://github.com/HHousen/PicoCTF-2021/blob/master/Reverse%20Engineering/Transformation/script.py)) by looping through the encoded flag and for each loop we:
   1. Shift the bits right to get the first letter in the pair.
   2. Convert the encoded character to bytes and get the last byte to get the second letter in the pair.
   3. Append the letters to the `flag` variable.

### Flag

`picoCTF{16_bits_inst34d_of_8_26684c20}`


---

# Agent Instructions: 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:

```
GET https://picoctf2021.haydenhousen.com/reverse-engineering/transformation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
