Magic of Numbers [PPC]

Magic of Numbers

Do you think Sherlock can beat a computer in math? nc 212.47.229.1 33004

Hint: There is an assumption that the computer does not always think the way you think.

Recon

The server sends:

Hey, hello! Just send me an answer to 9 simple examples, so I can check if my machine knows math well.

The math questions are floating point sums, but with the hint and the title of the challenge, we are probably searching for floating point rounding weirdness.

We do see some weirdness if running the sums in normal python, but it sounds like a guessing game.

Python 2.7.16 (default, Apr  6 2019, 01:42:57) 
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 0.1 + 0.2 + 0.3
0.6000000000000001
>>> 0.2 + 0.3 + 0.4
0.9
>>> 0.3 + 0.4 + 0.5
1.2
>>> 0.4 + 0.5 + 0.6
1.5
>>> 0.5 + 0.6 + 0.7
1.8
>>> 0.6 + 0.7 + 0.8
2.0999999999999996
>>> 0.7 + 0.8 + 0.9
2.4
>>> 0.8 + 0.9 + 0.10
1.8000000000000003
>>> 0.9 + 0.10 + 0.11
1.11
>>> 0.10 + 0.11 + 0.12
0.33

Code

Made an attempt using the following numbers and combinations, but didn't solve it.

#!/usr/bin/env python

from pwn import *
import sys
import re

a = ["0.6000000000000001", "0.9", "1.2", "1.5", "1.8", "2.0999999999999996", "2.4", "1.8000000000000003", "1.11", "0.33" ]

s = remote("212.47.229.1", 33004)

for i in range(10):
    print(s.recvuntil("[>] "))
    m = s.recvline().strip()
    print(m)
    # We did an eval here, but when combined with str, it just returns rounded n
umbers
    print(a[i])
    s.sendafter("Result: ", a[i] + "\n")

print(s.recvline())

Challenge update

Then the challenge was silently updated without any notifications. This time with only 1 calculation for floating point numbers.

$ python magic.py 
[+] Opening connection to 212.47.229.1 on port 33004: Done
======================================================================================================
Hey, hello! Just send me an answer to 9 simple examples, so I can check if my machine knows math well.
======================================================================================================
[>] 
0 + 1
1
[>] 
1 + 3
4
[>] 
2 + 5
7
[>] 
3 + 7
10
[>] 
4 + 9
13
[>] 
5 + 11
16
[>] 
6 + 13
19
[>] 
7 + 15
22
[>] 
8 + 17
25
[>] 
0.1 + 0.2
0.30000000000000004
FLAG{MaGiC_0f_NuMbErS}

Flag

FLAG{MaGiC_0f_NuMbErS}