Tags: reversing 

Rating: 3.0

# pydis2ctf - 490 points
I got 3 files in this challenge, It's about Pytecode. OK, let's start !!!

## Solution
To solve this, you have to read this: [https://docs.python.org/3/library/dis.html](https://docs.python.org/3/library/dis.html) , just read and rewrite it ;)
Here is disassemble of C1ipher:

```
2 0 LOAD_CONST 1 ('')
2 STORE_FAST 1 (ret_text)

3 4 LOAD_GLOBAL 0 (list)
6 LOAD_FAST 0 (text)
8 CALL_FUNCTION 1
10 GET_ITER
>> 12 FOR_ITER 42 (to 56)
14 STORE_FAST 2 (i)

4 16 LOAD_FAST 0 (text)
18 LOAD_METHOD 1 (count)
20 LOAD_FAST 2 (i)
22 CALL_METHOD 1
24 STORE_FAST 3 (counter)

5 26 LOAD_FAST 1 (ret_text)
28 LOAD_GLOBAL 2 (chr)
30 LOAD_CONST 2 (2)
32 LOAD_GLOBAL 3 (ord)
34 LOAD_FAST 2 (i)
36 CALL_FUNCTION 1
38 BINARY_MULTIPLY
40 LOAD_GLOBAL 4 (len)
42 LOAD_FAST 0 (text)
44 CALL_FUNCTION 1
46 BINARY_SUBTRACT
48 CALL_FUNCTION 1
50 INPLACE_ADD
52 STORE_FAST 1 (ret_text)
54 JUMP_ABSOLUTE 12

6 >> 56 LOAD_FAST 1 (ret_text)
58 RETURN_VALUE
```
```
STORE_FAST is mean a variable when you want to call a function or a list array, so i got this: ret_text = ''
FOR_ITER is made a loop with for command, ex: for i in range(19)
```
.... After you analyze it, you'll get a source code ;)
```
def function(text):
ret_text = ''
for i in list(text):
couter = text.count(i)
ret_text += chr((2 * ord(i)) - len(text))
return ret_text
```
## Final
Actually i analyzed C2cipher too, but it's troll because i tried to reversed this code but it isn't work, back to the C1cipher, i guess that ret_text is encode and text variable is the flag when you input it. So you have to rewrite it by using Reversing skill :v

```
cipher = '¤Ä°¤ÆªÔ\x86$\xa04\x9cÌ`H\x9c¬>¼f\x9c¦@HH\xa0\x84¨\x9a\x9a¢vÐØ'

def decrypt(text):
ret_text = ''
for i in list(text):
couter = text.count(i)
ret_text += chr(int((ord(i) + len(text)) / 2))
return ret_text

print(decrypt(cipher))
```
```
flag: csictf{T#a+_wA5_g0oD_d155aSe^^bLy}
```

chinhnt2k3July 22, 2020, 3:34 a.m.

So much troll. I tried both c1cipher(c2cipher(pt)) and c2cipher(c1cipher(pt)) and finally got tired and gave up.


En1gmaJuly 22, 2020, 5:38 a.m.

:v, troll in C2cipher bro :v