Rating:

# I Thought Trig Was Really Easy

## Description

After finishing a hard lesson in geometry class, Keith decided that he wanted to put your understanding of trig and python to the test. Can you solve his challenge?

[trig_is_really_hard.py](trig_is_really_hard.py)

## Solution

The ans in [trig_is_really_hard.py](trig_is_really_hard.py) was generated by:

```
for i in range(0, len(inp)):
for j in lots_of_nums(nice_math(get_number(inp[i]), len(inp) - i), i + 1):
out.append(nice_math(j, i + 1))
```

In which the length of lots_of_nums = (n//a+a//2+a%2) - (n//a-a//2) + 1 = a + 1
```
lots_of_nums = lambda n,a:(lambda r:[*r,n-sum(r)])(range(n//a-a//2,n//a+a//2+a%2))
```
We can see that the lenth of ans is 90 = 2 + 3 + ... + 13. Thus the len(inp) sould be 12.

So I looped through printable characters (which were substracted by 96) and check the genrated list is the same as ans by:
```
for i in range(0, 12):
for k in range(-64,31):
app = []
for j in lots_of_nums(nice_math(k, 12 - i), i + 1):
app.append(nice_math(j, i + 1))
if app == ans[(4+i)*(i+1)//2-2-i:(4+i)*(i+1)//2]: #(4+i)*(i+1)//2 = 2+3+...+(i+2)
for l in app:
out.append(l)
break
inp += chr(96+k)
```
The complete srcipt can be seen [here](trig_is_really_easy.py).

And finally it gave me the flag.

```
hsctf{:hyperthonk:}
```

Original writeup (https://github.com/kuruwa2/ctf-writeups/tree/master/HSCTF%206/I%20Thought%20Trig%20Was%20Really%20Easy).