Code Challenges

Ask programming questions in your event

Code Challenges allow CTFd to grade and evalute code submissions in a variety of programming languages. Code submissions are provided a stdin value which the submission must then process to get a stdout value.

Grading is done by creating a code flag alongside the code challenge. Code flags allow you to specify the stdin and stdout that the user’s code should receive and generate.

Test Cases

Each code flag for a code challenge is considered a seperate test case. The submission must pass all test cases (in this case a flag), in order for the challenge to be marked correct.

Reading input

A user’s submissions should read data from stdin and then process it somehow to generate the expected stdout. Here are the different supported ways to read stdin.

Directly

Users can read directly from stdin in their chosen programming language. This may have difficulties with detecting when stdin is empty depending on the challenge.

For example with Python code:

while True:
    try :
        line = input()
        # Process line
        print(line)
    except EOFError:
        # Break out if stdin is empty
        break

From a file

Users can read from the special input.txt file which contains the stdin value represented as a file.

For example with Python code:

with open("input.txt") as f:
    lines = f.read().splitlines()
    for line in lines:
        # Process line
        print(line)

Security Concerns

Leaking stdin

Code challenges support the ability to run the user’s submission and display the output to the user. However keep in mind that this may leak out the input test cases which may allow the user to cheat their way past the challenge.

Network Access

Code challenges by design do not support network access. If you have a specific use case for this reach out to support@ctfd.io to discuss.

Supported Languages

We currently support the following programming languages. However if you need a programming language reach out to support@ctfd.io and we can likely add support!

  • Python
  • C/C++
  • Java
  • NodeJS
  • Ruby

Last modified August 25, 2021