***Contains spoilers, obviously.***
The GCHQ (Government Communications Headquarters) released a hilariously infuriating Christmas card, which consisted of a logic puzzle, which once solved, led to more puzzles, which led to more puzzles, and so on.
I solved the first puzzle no problem. That revealed Part 2, a series of 6 multiple choice questions, all of which required a correct answer to move on. I got two of them, but was left at a loss for the other four. I gave it an honest try, but really wanted to see what Part 3 had in store. So, I turned to cheating. And, here’s how.
Clicking through the answers, you may notice that the URL contains the previous answer letter. For example, if your answers were A, B, C, D, E, and F, the final webpage (telling you that you were wrong) would have the URL: http://s3-eu-west-1.amazonaws.com/puzzleinabucket/ABCDEF.html
If you had enough time, you could type in each combination and see if that led to a “correct” URL. Obviously, that would be fairly time-consuming. Each of 6 questions had 6 possible answers, which means 6 ^ 6 = 46656 possibilities. You could save some time by including known correct answers. In my case, I had two answers of which I was confident. That left me with 6 ^ 4 = 1296 possibilities, still too many to inspect manually.
However, a simple Python script could load the pages fairly quickly (about once per second, or a maximum of 21.6 minutes), inspect the resulting webpage, and determine if it contains a message indicating that the combination was incorrect. If so, move onto next combination. If not, stop and print the correct combination.
Here’s the script:
import requests, time, sys from lxml import html opts = ['A','B','C','D','E','F'] # possible answers for i in opts: for j in opts: for k in opts: for l in opts: url = i + j + k + 'A' + l + 'E' # 4 unknown, 2 known time.sleep(1) # provide rest in between calls r = requests.get('http://s3-eu-west-1.amazonaws.com/puzzleinabucket/' + url + '.html') # make call tree = html.fromstring(r.text) # store page html if tree.xpath('//div[contains(., "Sorry - you did not get all the questions correct.")]/p//text()'): pass else: print "SUCCESS " + url sys.exit() # quit script once correct combination is found
And the final answer: DEFACE
The quiz is for charity, so don’t forget to donate here.