perfect bird
This is a dreamberd
script (renamed to GulfOfMexico
at the time of writing): https://github.com/TodePond/GulfOfMexico:
There is no public interpreter for it, but the rules are explained on the repo’s readme. The language is similar to JavaScript, so we can just write a script that converts it to valid JavaScript.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import re
with open("chall.db3") as file:
lines = file.readlines()
variables = {}
found_lifetime = True
while found_lifetime:
for index, line in enumerate(lines):
lifetime_declaration = re.search(r"<(\S+)>", line)
if lifetime_declaration is None:
found_lifetime = False
else:
found_lifetime = True
lifetime = lifetime_declaration.group(1)
line = re.sub(r"<(\S+)>", "", line)
lines.pop(index)
if lifetime == "Infinity":
lines.insert(0, line)
else:
lines.insert(max(0, index + int(lifetime)), line)
break
for i in range(len(lines)):
line = lines[i]
replace = {
"!": "",
"var var": "var",
"functi main () => {": "function main() {",
"const var": "var",
"const const const": "var",
"print(m)": "console.log(m)\nconsole.log(String.fromCharCode(...m))",
}
for key, value in replace.items():
line = line.replace(key, value)
variable_declaration = re.search(r"var (\d+)", line)
if variable_declaration is not None:
name = variable_declaration.group(1)
variables[name] = "_" + name
for key, value in variables.items():
line = re.sub(f"(?<!0x){key}", value, line)
subscript_declaration = re.search(r"(\S+)\[(\S+)\]", line)
if subscript_declaration is not None:
array = subscript_declaration.group(1)
subscript = subscript_declaration.group(2)
line = re.sub(r"(\S+)\[(\S+)\]", f"{array}[{subscript} + 1]", line)
semicolons = line.count(";")
if semicolons % 2 == 1:
line = line.replace(";" * semicolons, "!")
else:
line = line.replace(";" * semicolons, "")
lines[i] = line
print(variables)
with open("out.js", "w") as file:
for line in lines:
file.write(line)
file.write("main()")
This post is licensed under CC BY 4.0 by the author.