CorCTF is the first CTF organized by the Crusaders of Rust (aka Starrust Crusaders), an American and European collegiate team.
Crypto
Fibinary
The task is to decrypt the flag from the given two files enc.py
and flag.enc
. The following is the code for encryption.
fib = [1, 1] for i in range(2, 11): fib.append(fib[i - 1] + fib[i - 2]) def c2f(c): n = ord(c) b = '' for i in range(10, -1, -1): if n >= fib[i]: n -= fib[i] b += '1' else: b += '0' return b flag = open('flag.txt', 'r').read() enc = '' for c in flag: enc += c2f(c) + ' ' with open('flag.enc', 'w') as f: f.write(enc.strip())
First the code is generating a list with a total of 11 elements with the name fib
. Then the code reads the flag from a local file and passes each character to the function named c2f
. In the c2f
function, a 10 character string consisting of ‘1’ and ‘0’ is generated based on the if condition. Then the program writes to output to the file named flag.enc
file.
Instead of following the reverse path to decrypt the flag, I tried to bruteforce the flag. With the string
module in python, I wrote the following code.
#!/usr/bin/python3 import string s = list(string.printable) flag = ['10000100100','10010000010','10010001010','10000100100','10010010010','10001000000','10100000000','10000100010','00101010000','10010010000','00101001010','10000101000','10000010010','00101010000','10010000000','10000101000','10000010010','10001000000','00101000100','10000100010','10010000100','00010101010','00101000100','00101000100','00101001010','10000101000','10100000100','00000100100'] fib = [1, 1] for i in range(2, 11): fib.append(fib[i - 1] + fib[i - 2]) def decrypt(n): b = '' for i in range(10,-1,-1): if n >= fib[i]: n-=fib[i] b+= '1' else: b+='0' return b for i in flag: for j in s: if decrypt(ord(j)) == i: print(j,end="")
Running this will yield the flag.
flag: corctf{b4s3d_4nd_f1bp!113d}
That’s it folks. Happy hacking!!!