csictf 2020

CTF Writeup - https://ctftime.org/event/1081

Home csictf 2020 Writeups Home
22 July 2020


by raghul-rajasekar

I learnt Python in school but I have no clue what this is!



The contents of C1cipher and C2cipher appear to be Python disassembly. Manually converting this to Python code, we would have something like:

def C1cipher(text):
    ret_text = ''
    for i in list(text):
        counter = text.count(i)
        ret_text += chr(2*ord(i) - len(text))
    return ret_text

def C2cipher(inpString):
    xorKey = 'S'
    length = len(inpString)
    for i in range(length):
        inpString = inpString[:i] + chr(ord(inpString[i]) ^ ord(xorKey)) + inpString[i+1:]
    return inpString

The first cipher replaces each character i in the input text with chr(2*ord(i) - len(text)), while the second cipher XORs every character in the input text with 'S'. To reverse the first cipher, I wrote the following function:

def C1rev(text):
    ret = ''
    for i in text:
        ret += chr((ord(i)+len(text))//2)
    return ret

To reverse the second cipher, xor(inpString, 'S') is sufficient (xor function from the pwn library is used). However, only C1rev was enough to get the flag; seems like C2cipher wasn’t used at all.


tags: Reversing