Tags: misc scipy invaders0x1 

Rating:

# Baby Calculator

`nc 20.169.252.240 4200`

A good challenge to do writeup.

```sh
mj0ln1r@AHLinux:~/babycalc$ nc 20.169.252.240 4200
Welcome to the Baby Calculator! Answer 40 questions in a minute to get the flag.
The difference between your input and the correct answer must be less than 1e-6.
[+] Question 1:
Evaluate the integral of: 4/x from 3 to 7.
> Answer:

```

It was asking us to do integral of `4/x from 3 to 7`, It was easy to do with `scipy` module of python

```python
from scipy.integrate import quad
def compute_integral(func, lower_limit, upper_limit):
integral, error = quad(func, lower_limit, upper_limit)
return integral
def f(x):
return 4/x
compute_integral(f,3,7)

```

But it was difficult to answer 40 questions in a minute. So, I used `pwntools` to automate this process.

This is my solution script.

```python
from math import cos, exp, pi,sin
from scipy.integrate import quad
from pwn import *

def compute_integral(func, lower_limit, upper_limit):
integral, error = quad(func, lower_limit, upper_limit)
return integral
def f(x):
return eval(exp)
conn = remote('20.169.252.240',4200)
for i in range(40):
conn.recvuntil(b'Evaluate the integral of: ')
exp = conn.recvuntil(b' ').decode()
r = conn.recvuntil(b'.').decode().strip('.')
r = r.split(" ")
ranges = [int(r[1]),int(r[3])]
integral = compute_integral(f, ranges[0], ranges[1])
print(integral)
conn.recv()
conn.sendline(str(integral).encode())
if i == 39:
print(conn.recv())

# cvctf{B4by_m@7h_G14n7_5t3P}
```

> `Flag : cvctf{B4by_m@7h_G14n7_5t3P}`

# [Original Writeup](https://themj0ln1r.github.io/posts/cryptoversectf23)

Original writeup (https://themj0ln1r.github.io/posts/cryptoversectf23).