Rating:

For more PACTF write-ups, [check this out](https://leniumc.github.io/categories/CTF/).

We can easily figure out that the text file was in a language called JSFuck. Using an online decoder, we get this message.

```
Congrats! You've uncovered the truth. Now go here: ibarakaiev.shpp.me/pactf_s7fj43/ai.zip
```

From the given URL, we obtain [this](ibarakaiev.shpp.me/pactf_s7fj43/ai.zip) file. Looking through all of the files in the zip, there is one named ```script.js``` .

There was this line of code.
``` javascript
append_ai('The key is now stored securely in ("http://ibarakaiev.shpp.me/pactf_s7fj43/key_%d.txt", get_key_number(6, [16, 23, 16, 15, 42, 8])).', 30, 300);
```

And this function.
``` javascript
// this function returns the number needed to access key_%d.txt
function get_key_number(n, arr) {
// TODO: implement solution to the following problem

/**
* You are given a sequence _s_ consisting of _N_ integers. You can divide it to
* two sequences _p_ and _q_ such that every element of your sequence belongs exactly
* to one of these sequences.
*
* Let _B_ be the sum of elements belonging to _p_, and _C_ be the sum of elements
* belonging to _C_. Note: if some of the sequences is empty then its sum is 0).
* What is the maximum possible value of _B_ - _C_
*/
}
```

Looking at the function description, we find that the integer in the file name ```key_%d.txt``` must be the sum of ```[16, 23, 16, 15, 42, 8]```, which is 120. Going to that website, we obtain another text file.

```
But you'll have to decrypt it first! The following text is displayed using byfes (it's like bytes but only 5 bits).

mrxwozAp

PACTFSCII is as follows (it's like ASCII but for PACTF). PACTF system only accepts ASCII characters, however.
0 - a
1 - b
2 - c
3 - d
4 - e
5 - f
6 - g
7 - h
8 - i
9 - j
10 - k
11 - l
12 - m
13 - n
14 - o
15 - p
16 - q
17 - r
18 - s
19 - t
20 - u
21 - v
22 - w
23 - x
24 - y
25 - z
26 - P
27 - A
28 - C
29 - T
30 - F
31 - \0
```

Representing the given text in ```byfes``` in binary form, and we obtain this result.

```
01100 10001 10111 10110 01110 11001 11011 01111
```

Recombining these binary numbers in groups of 8 and converting each group to an ascii character reveals the flag.

```
doggo
```

Original writeup (https://leniumc.github.io/2018/05/16/pactf_2018_round_2_part_2/).