Contents

Insomni'hack teaser 2023 - Artscii

This is the solution of the challenge “Artscii” given during the Insomni’hack teaser 2023. It consists in recovering a flag written in ASCII art and scrambled.

Description

Can you read the flag?

generate.py

output.txt

Details

Points: 98

Category: Misc

Author: 123Soleil

Solution

The Python script shows that the flag is written in uppercase letters and digits and composed of 3 words separated by underscores. The flag is generated by a package called art using the medium fonts. I first reuse the code to generate the list of medium fonts list and I could guess from the text file that the first word is MISC. Thus bruteforcing among all the fonts until the same correct first line is generated revealed the three fonts used by the algorithm:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
from my_art.art.art import RND_SIZE_DICT

medium_font = RND_SIZE_DICT["medium_list"]
good_line = "##   ##  #     ####  #    #  ##  "

for f1 in medium_font:
    text1 = art.text2art("MISC", font=f1, chr_ignore=False)
    if re.search(r'^[ #\n]*$', text1):
        for f2 in medium_font:
            text2 = art.text2art("MISC", font=f2, chr_ignore=False)
            if re.search(r'^[ #\n]*$', text2):
                for f3 in medium_font:
                    text3 = art.text2art("MISC", font=f3, chr_ignore=False)
                    if re.search(r'^[ #\n]*$', text3):
                        res = mergeText(text1,text2)
                        res = mergeText(res,text3)
                        if res.split("\n")[0] == good_line:
                            print(f1, f2, f3)
    print("Finished")

The script outputs combination of the fonts future_2, z-pilot, green_be and ghost_bo. After playing with the script it appeared that the first three fonts were used and not the last one.

By visual inspection I came up with the flag INS{MISC_MAYHEM_A7R93Yxx7x} with three missing characters. I chose to bruteforce them:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
good_line = "   #     #        ##  #     # # #   ###   # #    ##    ## #   #  # #    #       ## ####"
for c0 in string.ascii_uppercase + string.digits:
    for c1 in string.ascii_uppercase+ string.digits:
        for c2 in string.ascii_uppercase+ string.digits:
            content = "A7R93Y" + c0 + c1 + "7" + c2
            text1 = art.text2art(content, font="future_2", chr_ignore=False)
            text2 = art.text2art(content, font="green_be", chr_ignore=False)
            text3 = art.text2art(content, font="z-pilot", chr_ignore=False)
            res = mergeText(text1,text2)
            res = mergeText(res,text3)

            if res.split("\n")[0].startswith(good_line):
                print(content)

It printed three results and the first one was the correct one giving the flag INS{MISC_MAYHEM_A7R93Y4E7H}.