Writeup for Fibinary (Crypto) - Crusaders of Rust (cor) CTF (2021) 💜
Challenge Description
Warmup your crypto skills with the superior number system!
Solution
# first 11 numbers in fibonacci sequence (excl zero) - will be used by c2f()fib = [1,1]for i inrange(2, 11): fib.append(fib[i -1] + fib[i -2])print('fib: '+str(fib))defc2f(c): n =ord(c) b =''# looping from 10 to 0 (reverse order through fib)for i inrange(10, -1, -1):# if our char is greater than current fib[i]if n >= fib[i]:# subtract fib[i] from char and add '1' to binary n -= fib[i] b +='1'else:# if char is smaller, add '0' to binary b +='0'return bflag ='fake_flag'enc =''# perform encryption on fake flag and printfor c in flag: enc +=c2f(c)+' 'print('encrypted: '+str(enc.strip()))# OK so lets add a decrypt function..deff2c(b): c =0# loop through byte, incrementing by fib[i] when '1' is foundfor i inrange(10, -1, -1):if b[i]=='1': c += fib[i]returnchr(c)dec =''# loop through the bytes, decrypting each one and returning charfor b instr(enc.strip()).split(" "): dec +=f2c(b[::-1])# reverse the byteprint('decrypted: '+ dec)