Ostrich Lab - CTF Write Ups

Simple Programming - ctflearn.com

2024-11-08

Author: Aaron 'theHastyOne' Hasty

Simple Programming on CTFlearn

Download the file data.dat

Create the following script in python

# Open the file and read its lines
with open('data.dat', 'r') as file:
    lines = file.readlines()

# Initialize the counter
count = 0

# Loop through each line in the file
for line in lines:
    # Remove any trailing whitespace or newline characters
    line = line.strip()

    # Count the number of '0's and '1's
    num_zeros = line.count('0')
    num_ones = line.count('1')

    # Check the conditions and update the counter
    if num_zeros % 3 == 0 or num_ones % 2 == 0:
        count += 1

# Output the result
print(f"Number of lines meeting the conditions: {count}")

Number of lines meeting the conditions: 6662