Being provided a txt file titled “long.txt” with the challenge title of “Count them all”, and the description “One important aspect of an inventory is to count all the swords you’ve got. Count them all.” was the premise for a challenge in the recent School CTF. Opening the file in a text editor (I used Notepad++) we can see that the file is comprised of a single line made up of a large amount of 1s. Using python we can easily open up the file and count the amount of 1s. It would be quite boring to do it manually.
Using the script:
x = open("long.txt", "r") start = 0 for y in x.readline(): if y == str(1): start += int(y) print start
we find that the sum of all of the numbers is 1111103. But that doesn’t seem to be the key.
Instead let’s check to see if everything is in fact a 1. With a slight modification to the previous script:
x = open("long.txt", "r") for y in x.readline(): if y != str(1): print y
we get the result:
s u m i n h e x
or more cohesively: suminhex
Now that we’ve received our hint, we can take our previous value of 1111103 and use an online calculator (Google “1111103 in hex”) to convert that to hex or use Python’s built in hex function:
Either will result in “0x10f43f” which if we drop off the 0x will result in the key: 10f43f