You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -17,18 +17,19 @@ As a _bird_ soaring through the sky, you seek the _perfect language_, and then..
17
17
18
18
## Writeup
19
19
20
-
Opening the `chall.db3` file, we find a strange javascript-like programming language.
21
-
The code has some strange symbols and conventions, and without a guide, it's hard to understand what it does.
20
+
Opening the `chall.db3` file, I come across a weird programming language that looks kind of like JavaScript. The code is full of strange symbols and conventions, and without a guide, it’s pretty hard to figure out what it does.
22
21
23
-
The first thing I try to always do is to look at the challenge description for hints. In this case, we have the words "bird" and "perfect language" in italic.
24
-
I try to search the web for "bird perfect language programming".
25
-
As the first result, I get the streamer ThePrimeTime, who has [a video on this "programming language"](https://www.youtube.com/watch?v=tDexugp8EmM).
22
+
My go-to move is always to check the challenge description for hints. Here, the words _bird_ and _perfect language_ are italicized, which seems important. So, I search for "bird perfect language programming" online.
23
+
24
+
The first result is [a video by the streamer ThePrimeTime][video], where he talks about this exact programming language.

28
29
29
-
From the description of the video, I get back to the GitHub repository describing this language: <https://github.com/TodePond/GulfOfMexico>
30
+
From the video's description, I find my way back to the GitHub repository that explains this language: <https://github.com/TodePond/GulfOfMexico>.
30
31
31
-
Apparently the language was called "DreamBerd", but now it seems to be called "GulfOfMexico".
32
+
It looks like it was originally called "DreamBerd," but now it goes by "GulfOfMexico."
32
33
33
34
## DreamBerd - A Perfect Language
34
35
@@ -38,15 +39,17 @@ Apparently the language was called "DreamBerd", but now it seems to be called "G
38
39
>print("Hello world")!
39
40
>```
40
41
41
-
I think about ways to decypher the code, and I come up with the idea of writing
42
-
a script to convert the code to a more readable form. I first think about
43
-
converting it to Python, but then I change my mind and decide to convert it to
44
-
JavaScript, as it's more similar to the original language.
42
+
I start thinking about ways to decipher the code and come up with the idea of writing a script to rewrite it into an existing language (one with an existing interpreter!).
43
+
44
+
At first, I consider converting it to Python, but then I realize JavaScript would be a better choice since it’s closer to the original language.
45
45
46
-
I write a Python script to convert the code to JavaScript, and then I run it to get the output.
46
+
So, I write a Python script to convert the code to JavaScript and run it to see the output.
47
47
48
48
### Converting DreamBerd to JavaScript
49
49
50
+
The key here is that we don’t need a _perfect_ (pun intended) conversion—just something accurate enough to run the challenge code.
51
+
It doesn’t have to handle every possible DreamBerd program, just this one.
52
+
50
53
The first thing we need to do is to fix the lifetimes in the code.
51
54
52
55
> Gulf of Mexico has a built-in garbage collector that will automatically clean
@@ -109,9 +112,6 @@ program = "".join(program)
109
112
110
113
Then we need to replace each "strange lang" construct with the corresponding JavaScript construct.
111
114
112
-
The thing to keep in mind here is that we don't need to be _perfect_ (pun intended) in the conversion. We just need to
113
-
be accurate enough to run the challenge code (as opposed to EVERY DreamBerd code).
114
-
115
115
-`!` -> nothing
116
116
117
117
```python
@@ -207,7 +207,8 @@ $ node chall_ok.js
207
207
208
208
```
209
209
210
-
Apparently, the code is an array of integers. We can convert it to ASCII to get the flag.
210
+
The result we get is an array of integers.
211
+
We can convert it to ASCII to get the flag.
211
212
212
213
```python
213
214
#!/bin/env python3
@@ -223,98 +224,9 @@ for i in range(0, len(m)):
223
224
print(chr(m[i]), end="")
224
225
```
225
226
226
-
And we get the flag.
227
-
228
227
```shell
229
228
$ python3 decode.py
230
229
TRX{tHi5_I5_th3_P3rf3ct_l4nGU4g3!!!!!!}
231
230
```
232
231
233
-
## Full script
234
-
235
-
<details>
236
-
237
-
```python
238
-
#!/bin/env python3
239
-
import sys
240
-
import re
241
-
242
-
243
-
lines = sys.stdin.readlines()
244
-
245
-
246
-
deffix_lifetimes(lines):
247
-
new_lines = []
248
-
249
-
for i, line inenumerate(lines):
250
-
match = re.match(r".+<(.+)>.+", line)
251
-
ifnot match:
252
-
new_lines.append(line)
253
-
continue
254
-
255
-
lifetime = match.group(1)
256
-
257
-
if lifetime =="Infinity":
258
-
new_lines.append(line)
259
-
continue
260
-
261
-
lifetime =int(lifetime)
262
-
263
-
if lifetime >=0:
264
-
line = line.replace(f"<{lifetime}>", "")
265
-
new_lines.append(line)
266
-
continue
267
-
268
-
new_pos =max(len(new_lines) + lifetime, 0)
269
-
270
-
# remove the invalid lifetime
271
-
line = line.replace(f"<{lifetime}>", "")
272
-
new_lines.insert(new_pos, line)
273
-
274
-
print(f"Moved line {i +1} -> {new_pos +1}", file=sys.stderr)
275
-
276
-
return new_lines
277
-
278
-
279
-
program = fix_lifetimes(lines)
280
-
program ="".join(program)
281
-
282
-
283
-
284
-
program = re.sub(r"!+", "", program)
285
-
for i inrange(1, 100):
286
-
program = re.sub(r";([\w|!|(|)]+)", r"!(\1)", program)
287
-
288
-
program = program.replace("const const const", "let")
289
-
program = program.replace("const const", "let")
290
-
program = program.replace("const var", "let")
291
-
program = program.replace("var var", "let")
292
-
293
-
program = re.sub(r"let (\d+)", r"let var_\1", program)
294
-
295
-
296
-
program = program.replace("42 +=", "var_42 +=")
297
-
program = program.replace("42 -=", "var_42 -=")
298
-
program = program.replace("42 *=", "var_42 *=")
299
-
program = program.replace("42 ^ ", "var_42 ^ ")
300
-
program = program.replace("42 = ", "var_42 = ")
301
-
program = program.replace("42 * ", "var_42 * ")
302
-
program = program.replace("42 / ", "var_42 / ")
303
-
program = program.replace("42 % ", "var_42 % ")
304
-
program = program.replace("42 + ", "var_42 + ")
305
-
program = program.replace("42 - ", "var_42 - ")
306
-
program = program.replace("!42", "!var_42")
307
-
308
-
309
-
program = re.sub("<Infinity>", "", program)
310
-
program = re.sub(r"functi (.+?)\(\) =>", r"function \1()", program)
311
-
program = re.sub(r"print", "console.log", program)
312
-
313
-
# array starts at -1 ...
314
-
program = re.sub(r"(\w+)\[(.+)\]", r"\1[\2 + 1]", program)
0 commit comments