Skip to main content

Code Challenges

caution

Code Challenges are only available on Hosted CTFd instances or Enterprise CTFd Instances

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.

info

CTFd will always normalize line endings to Linux line endings (i.e. \n) in stdin and stdout when processing or grading.

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 [email protected] to discuss.

Supported Languages

We currently support the following programming languages. However if you need a programming language reach out to [email protected] and we can likely add support!

Python

  • 2.7
  • 2.5
  • 3.6
  • 3.8

C/C++

  • C++14

Java

  • 11

NodeJS

  • 8.x

Ruby

  • 2.5

Bash

  • 4.4

Golang

  • 1.18

Rust

  • 1.62.1