All write-ups

CTF Write-up · Coding

Longest Word

Identifying the longest token in a supplied article file.

Source: EOman 2022 Category: Coding 15 points Easy

Challenge

The flag is the longest word in the attached article file.

Analysis

The file is read, flattened into a single list of whitespace-separated tokens, and the token of maximum length is selected. Using len as the key avoids any manual length comparison.

Solution

with open('article.txt') as f:
    words = [y for x in f.readlines() for y in x.split()]
    longest = max(words, key=len)
    print(longest, "and it is", len(longest), "characters long")

The longest token printed is the flag.

← Back to all write-ups