C3

Challenge Overview

This is the Custom Cyclical Cipher!

Download the ciphertext here.

Download the encoder here.

Enclose the flag in our wrapper for submission. If the

flag was "example" you would submit

"picoCTF{example}".

Solution

To get the files: wget https://artifacts.picoctf.net/c_titan/47/ciphertext https://artifacts.picoctf.net/c_titan/47/convert.py

There is a ciphertext file that is given and the script that was used to encode.

Given (convert.py):

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)

The first part of the code is just the way the Python file takes in the image. So to run the encoding process it would be with this command: python3 convert.py file. Two lookup variables are preset, and a loop that goes over every character provided in the file that was passed in. Cur is set to the n character position in the lookup1 variable. Then out takes that number from cur and subtracts prev which is initially 0. Then it uses "mod 40" to make sure it doesn't exceed the length of the variable as there are 40 characters stored. This modified number is used as the index for the lookup2 variable to get a new letter. Then prev is set to cur and the process starts again for each character in the file.

First script:

import sys

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

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

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

print(decrypted_message)

The only thing that changed to make it decode was flipping the portion in the for loop. This means taking the char from lookup2 instead of lookup1 initially. Then do cur + prev instead of cur - prev with the lookup1 variable instead of lookup2. Lastly, setting prev to decrypted_char_index instead of cur. This reverses the process. By running python3 with that script it gives this output:

#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

Save this as "decrypted.txt". This is code written in python2 so this script is converted to python3 and removed some minor redundancies.

Second Script:

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

for i in range(len(chars)):
    if i == (b * b * b):
        print(chars[i], end="")
        b += 1

print()

By using the second script with the original output (decrypted.txt) passed in, the output characters to get the flag is given.

Take the characters given by that and put it in the picoCTF wrapped format picoCTF{output}.

Flag: picoCTF{adl...}