> For the complete documentation index, see [llms.txt](https://kabinet.gitbook.io/ctf-writeup/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kabinet.gitbook.io/ctf-writeup/2024/greyctf-2024/poly-playground.md).

# Poly Playground

## Description

Magicians love to create things out of thin air. This time our secret wizards have created a playground. Test out your wizardry here! Comment Suggest edit

Author: jloh02

nc challs.nusgreyhats.org 31113

***

## Solve

Basicailly its a math question, finding cofficients of quadratic, cubic and quintic equation. I used chatgpt to write the script ot calculate the cofficient.

Note, I dont fully understand the math behind this, was just solving cause my team were busy with other challenges.

<figure><img src="/files/UbTQaoLrPwvZqVhDQ0FA" alt=""><figcaption></figcaption></figure>

Script

```python
from pwn import *

host, port = "challs.nusgreyhats.org", 31113

conn = remote(host,port)
conn.recvuntil(b"Here's your first problem...\n")


def level1(root1, root2):
    sum_of_roots = root1 + root2
    product_of_roots = root1 * root2

    b_over_a = -sum_of_roots
    c_over_a = product_of_roots

    b = b_over_a
    c = c_over_a

    a = 1

    return a, b, c

def level2(roots):
    sum_of_roots = sum(roots)
    product_of_pairs = roots[0] * roots[1] + roots[0] * roots[2] + roots[1] * roots[2]
    product_of_all = roots[0] * roots[1] * roots[2]

    b_over_a = -sum_of_roots
    c_over_a = product_of_pairs
    d_over_a = -product_of_all

    b = b_over_a
    c = c_over_a
    d = d_over_a

    a = 1

    return a, b, c, d

def level3(roots):
    sum_of_roots = sum(roots)
    product_of_pairs = sum(roots[i] * roots[j] for i in range(len(roots)) for j in range(i + 1, len(roots)))
    product_of_triples = sum(roots[i] * roots[j] * roots[k] for i in range(len(roots)) for j in range(i + 1, len(roots)) for k in range(j + 1, len(roots)))
    product_of_all = roots[0] * roots[1] * roots[2] * roots[3]

    b_over_a = -sum_of_roots
    c_over_a = product_of_pairs
    d_over_a = -product_of_triples
    e_over_a = product_of_all

    b = b_over_a
    c = c_over_a
    d = d_over_a
    e = e_over_a

    a = 1

    return a, b, c, d, e

def level4(roots):
    sum_of_roots = sum(roots)
    product_of_pairs = sum(roots[i] * roots[j] for i in range(len(roots)) for j in range(i + 1, len(roots)))
    product_of_triples = sum(roots[i] * roots[j] * roots[k] for i in range(len(roots)) for j in range(i + 1, len(roots)) for k in range(j + 1, len(roots)))
    product_of_quadruples = sum(roots[i] * roots[j] * roots[k] * roots[l] for i in range(len(roots)) for j in range(i + 1, len(roots)) for k in range(j + 1, len(roots)) for l in range(k + 1, len(roots)))
    product_of_all = roots[0] * roots[1] * roots[2] * roots[3] * roots[4]

    b_over_a = -sum_of_roots
    c_over_a = product_of_pairs
    d_over_a = -product_of_triples
    e_over_a = product_of_quadruples
    f_over_a = -product_of_all

    b = b_over_a
    c = c_over_a
    d = d_over_a
    e = e_over_a
    f = f_over_a

    a = 1

    return a, b, c, d, e, f


while True:
    p = ''
    p = conn.recvuntil(b'Present the coefficients of your amazing equation: ')
    p = p.split(b'\n')
    roots = p[2]
    levels = int(p[1].strip(b':').split(b' ')[1])
    numbers = roots.split(b' ')[1].split(b',')

    if levels < 21 :
        conn.sendline(f'1,{int(numbers[0]) * -1}')

    elif 20 < levels < 41:
        a,b,c = level1(int(numbers[0]),int(numbers[1]))
        conn.sendline(f'{a},{b},{c}')

    elif 40 < levels < 61:
        a,b,c,d = level2([int(numbers[0]),int(numbers[1]),int(numbers[2])])
        conn.sendline(f'{a},{b},{c},{d}')
    elif 60 < levels < 81:
        a,b,c,d,e = level3([int(numbers[0]),int(numbers[1]),int(numbers[2]),int(numbers[3])])
        conn.sendline(f'{a},{b},{c},{d},{e}')
    elif 80 < levels < 100:
        test = [int(numbers[0]),int(numbers[1]),int(numbers[2]),int(numbers[3]),int(numbers[4])]
        a,b,c,d,e,f = level4(test)
        conn.sendline(f'{a},{b},{c},{d},{e},{f}')
    
    if levels == 100:
        test = [int(numbers[0]),int(numbers[1]),int(numbers[2]),int(numbers[3]),int(numbers[4])]
        a,b,c,d,e,f = level4(test)
        conn.sendline(f'{a},{b},{c},{d},{e},{f}')
        conn.recvuntil(b"Here's your flag!\n")
        print(conn.recvline())
        quit()
```

<figure><img src="/files/2cT0j9uwpOS47fgoGKq4" alt=""><figcaption></figcaption></figure>

Flag: grey{l0oks\_lik3\_sOm3one\_c4n\_b3\_a\_po1ynomia1\_w1z4rd}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://kabinet.gitbook.io/ctf-writeup/2024/greyctf-2024/poly-playground.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
