Two Truths and a Fib
Programming

Problem

Can you catch the fibber?
nc umbccd.io 6000
Author: Trashcanna

Solution

1
import math
2
from pwn import *
3
​
4
# A utility function that returns true if x is perfect square
5
def isPerfectSquare(x):
6
s = int(math.sqrt(x))
7
return s*s == x
8
​
9
# Returns true if n is a Fibinacci Number, else false
10
def isFibonacci(n):
11
​
12
# n is Fibinacci if one of 5*n*n + 4 or 5*n*n - 4 or both
13
# is a perferct square
14
return isPerfectSquare(5*n*n + 4) or isPerfectSquare(5*n*n - 4)
15
​
16
conn = remote('umbccd.io', 6000)
17
​
18
done = False
19
while not done:
20
print(conn.recvuntil('['))
21
arr = eval('[' + conn.recvline().decode())
22
​
23
print(arr)
24
print(conn.recv())
25
​
26
for num in arr:
27
if isFibonacci(num):
28
print(num)
29
conn.send(str(num) + '\r\n')
30
break
31
​
32
print(conn.recv())
33
​
34
conn.close()
Copied!
Eventually we get the flag:
Copy link