Tags: crypto caesar_shift number_theory 

Rating:

This one was pretty straight forward. The hardest part was calculating fibbonacci numbers quickly, but luckily, there's a formula for that! It's called [Binet's formula](https://artofproblemsolving.com/wiki/index.php/Binet%27s_Formula). With this, we can create a simple script that reads from the terminal, does the shift, and sends it back to the terminal. The program eventually crashes once it recieves an invalid input from receiving the flag, but hey, at least it gives you the flag ¯\\\_(ツ)_/¯

```
import struct
import socket
import math
from caesarcipher import CaesarCipher

s = socket.socket()
s.connect(("misc.2020.chall.actf.co", 20300))

def Fib(n): #binet's formula
return int((1/math.sqrt(5))*((((1+math.sqrt(5))/2)**n) - (((1-math.sqrt(5))/2)**n)))

while True:
r = s.recv(1024).decode().strip()
print(r)
string = r[r.find("Shift") +6: r.find("by")-1 ].strip()
shift = Fib(int(r[r.find("n=") +2:r.find("\\n:")].rstrip()))

result = CaesarCipher(string, offset=shift)
s.send(result.encoded.encode() + b"\n")
```