> For the complete documentation index, see [llms.txt](https://ravins-organization.gitbook.io/ctf-writeups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ravins-organization.gitbook.io/ctf-writeups/2024/picoctf-2024/crypto/c3.md).

# C3

**Description**

This is the Custom Cyclical Cipher!Download the ciphertext [here](https://artifacts.picoctf.net/c_titan/47/ciphertext). Download the encoder [here](https://artifacts.picoctf.net/c_titan/47/convert.py). Enclose the flag in our wrapper for submission. If the flag was "example" you would submit "picoCTF{example}".

The encoder given was,&#x20;

```python
import sys
chars = ""
from fileinput import input
for line in input():
  chars += line

lookup1 = "\n \"#()*+/1:=[]abcdefghijklmnopqrstuvwxyz"
lookup2 = "ABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrst"

out = ""

prev = 0
for char in chars:
  cur = lookup1.index(char)
  out += lookup2[(cur - prev) % 40]
  prev = cur

sys.stdout.write(out)

```

So after seeing the previous challenge, I turned to ChatGPT, which after a bit of back and forth, I obtained this script:

```python
import sys

ciphertext = "DLSeGAGDgBNJDQJDCFSFnRBIDjgHoDFCFtHDgJpiHtGDmMAQFnRBJKkBAsTMrsPSDDnEFCFtIbEDtDCIbFCFtHTJDKerFldbFObFCFtLBFkBAAAPFnRBJGEkerFlcPgKkImHnIlATJDKbTbFOkdNnsgbnJRMFnRBNAFkBAAAbrcbTKAkOgFpOgFpOpkBAAAAAAAiClFGIPFnRBaKliCgClFGtIBAAAAAAAOgGEkImHnIl"

lookup1 = "\n \"#()*+/1:=[]abcdefghijklmnopqrstuvwxyz"
lookup2 = "ABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrst"

out = ""

prev = 0
for char in ciphertext:
    cur = lookup2.index(char)
    out += lookup1[(cur + prev) % 40]
    prev = (cur + prev) % 40

sys.stdout.write(out)

```

When run, you should be able to obtain the following script from the ciphertext:

```python
#asciiorder
#fortychars
#selfinput
#pythontwo

chars = ""
from fileinput import input
for line in input():
    chars += line
b = 1 / 1

for i in range(len(chars)):
    if i == b * b * b:
        print chars[i] #prints
        b += 1 / 1

```

As we can see, we obtained a Python2 script which if we run,&#x20;

```
cat part2.py | python part2.py
```

We obtain the flag of

&#x20;![](https://175444261-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyxEI13wXOyST4LLTOUiS%2Fuploads%2FLqWPF4aRT9Jx2nBduQpY%2FScreenshot%202024-03-27%20at%209.17.23%20PM.png?alt=media\&token=ca3f47c8-c76f-4a5f-8aea-a74c86463e57)

```
picoCTF{adlibs}
```
