pydis2ctf

点击此处获得更好的阅读体验


WriteUp来源

https://dunsp4rce.github.io/csictf-2020/reversing/2020/07/22/pydis2ctf.html

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:

1
2
3
4
5
6
7
8
9
10
11
12
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:

1
2
3
4
5
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.

Flag

1
csictf{T#a+_wA5_g0oD_d155aSe^^bLy}