예제 #1
0
    def do_compute(self):
        # step 1, get information from web source
        bell_url = TextHelper.find_text_between_tag(self.web_source,
                                                    '<a href="', '">')
        bell_url = WebHelper.join_url(self.url, bell_url)
        print "Find some url: %s" % bell_url
        zigzag_jpg = TextHelper.find_text_between_tag(self.web_source,
                                                      '<img src="', '"> <!--')
        zigzag_jpg = WebHelper.join_url(self.url, zigzag_jpg)
        print "Find a picture: %s" % zigzag_jpg
        gif_prompt = TextHelper.find_text_between_tag(self.web_source,
                                                      'did you say ', '? -->')
        gif_url = WebHelper.change_suffix_url(zigzag_jpg, gif_prompt)
        print "Get a gif picture: %s" % gif_url

        # step 2, deal with gif
        img = ImageHelper.create_image_from_web(gif_url, self.user,
                                                self.password)
        img_content = img.tobytes()
        img_plt = img.palette.getdata()[1][::3]
        trans = string.maketrans("".join([chr(i) for i in range(256)]),
                                 img_plt)
        img_tran = img_content.translate(trans)
        diff = ["", ""]
        img = Image.new("1", img.size, 0)
        for i in range(1, len(img_content)):
            if img_content[i] != img_tran[i - 1]:
                diff[0] += img_content[i]
                diff[1] += img_tran[i - 1]
                img.putpixel(((i - 1) % img.size[0], (i - 1) / img.size[0]), 1)
        img.show(
        )  # two words shows in picture: 'not', 'word', between is an key
        text = bz2.decompress(diff[0])
        auth = set()
        for i in text.split():
            if not keyword.iskeyword(i):
                auth.add(i)
        # print repeat, switch, ../ring/bell
        auth = list(auth)
        print auth
        for item in auth:
            if 'html' in item:
                next_level_url = WebHelper.join_url(self.url, item)
                auth.remove(item)
        try:
            content_ignore = WebHelper.get_auth_web_source(
                next_level_url, auth[0], auth[1])
            self.result.set_user_password(auth[0], auth[1])
            print "Set next level user, password = (%s, %s)" % (auth[0],
                                                                auth[1])
        except HTTPError:
            self.result.set_user_password(auth[1], auth[0])
            print "Set next level user, password = (%s, %s)" % (auth[1],
                                                                auth[0])

        # step 3, set next level url
        self.set_next_level_url(next_level_url)
예제 #2
0
    def do_compute(self):
        # step 1, get information from web source
        print TextHelper.find_text_between_tag(self.web_source, '<title>',
                                               '</title>')
        print "words above indicate us to explore the maze from top to bottom"

        maze_prompt = TextHelper.find_text_between_tag(self.web_source,
                                                       '<img src="', '">')
        maze_img = ImageHelper.create_image_from_web(
            WebHelper.join_url(self.url, maze_prompt), self.user,
            self.password)
        width, height = maze_img.size

        print "Find entrance in the top"
        for i in range(width):
            if maze_img.getpixel((i, 0))[2] == 0:
                entrance = (i, 0)
                print "(width=%d, height=0), pixel=(%s)" % (
                    i, maze_img.getpixel(entrance))
                break

        print "Find export at the bottom"
        for i in range(width):
            if maze_img.getpixel((i, height - 1))[2] == 0:
                export = (i, height - 1)
                print "(width=%d, height=%d), pixel=(%s)" % (
                    i, height - 1, maze_img.getpixel(export))

        # step 2, get out of the maze
        queue = T24.go_maze(maze_img, entrance, export)

        # step 3, get information from path
        zip_file = 'maze.zip'
        open('maze.zip', 'wb').write(''.join(
            [chr(maze_img.getpixel(pos[0])[0]) for pos in queue[1::2]]))
        FileHelper.unzip_to_directory(zip_file, '.')

        # step 4, get prompt information from picture
        maze_jpg = 'maze.jpg'
        ImageHelper.show_from_file(maze_jpg)
        prompt_words = 'lake'
        print "Get %s in the picture" % prompt_words
        self.set_prompt(prompt_words)

        # step 5, clean unused files
        FileHelper.remove_file(maze_jpg)
        FileHelper.remove_file(zip_file)
예제 #3
0
    def do_compute(self):
        # step 1, get information from web source
        png_url = TextHelper.find_text_between_tag(self.web_source, '<img src="', '" border="')
        png_url = WebHelper.join_url(self.url, png_url)
        print "Get png from web url: %s" % png_url
        bell_png = ImageHelper.create_image_from_web(png_url, self.user, self.password)
        green = bell_png.split()[1]
        message = ""
        for a, b in T28.paired(green.getdata()):
            diff = abs(a - b)
            if diff != 42:
                message += chr(diff)
        print 'Prompt Message: %s' % message   # whodunnit().split()[0] ?

        # step 2, set prompt
        prompt = self.whodunnit().split()[0]
        self.set_prompt(prompt.lower())
예제 #4
0
    def do_compute(self):
        # step 1. get information from web source
        print TextHelper.find_text_between_tag(self.web_source, '<!--\n',
                                               '\n-->')
        beer_url = TextHelper.find_text_between_tag(self.web_source,
                                                    '<img src="',
                                                    '" border="0"')
        beer_url = WebHelper.join_url(self.url, beer_url)
        print beer_url
        beer_url = WebHelper.url_add(beer_url)
        beer_url = WebHelper.change_suffix_url(beer_url, 'png')

        # step 2. try out this picture
        beer_img = ImageHelper.create_image_from_web(beer_url, self.user,
                                                     self.password)
        data = list(beer_img.getdata())
        local_dir = 'img_data'
        FileHelper.mkdir(local_dir)
        print len(data)
        count = 0
        while len(data) > 0:
            if self.is_int_sqrt(len(data)) and len(data) > 0:
                count += 1
                size = int(math.sqrt(len(data)))
                print "data length = %i, sqrt value = %i" % (len(data), size)
                new_img = Image.new('RGB', (size, size))
                new_img.putdata(data)
                new_img.save(os.path.join(local_dir, 'img_%i.png' % count))
            max_value = max(data)
            data = [x for x in data if x != max_value]

        # step 3, Get hint from these pictures
        print "check png under %s, you will find many characters!" % local_dir
        prompt = 'gremlins'
        print "but only characters %s are in square" % str(list(prompt))
        self.set_prompt(prompt)
        FileHelper.remove_folder(local_dir)
예제 #5
0
    def do_compute(self):
        # step 1, get information from web source
        question = TextHelper.find_text_between_tag(self.web_source, '<title>',
                                                    '</title>')
        print "The title asked us: %s" % question
        answer = ("kohsamui", "thailand")
        self.result.set_user_password(answer[0], answer[1])
        print "Set next level user, password = (%s, %s)" % answer
        print "Search google by this photograph, you can find the place: %s, %s" % answer
        prompt = TextHelper.find_text_between_tag(self.web_source, '<a href="',
                                                  '"><img src')
        new_url = WebHelper.join_url(self.url, prompt)
        print "Get prompt jpg url: %s" % new_url
        new_web_content = WebHelper.get_auth_web_source2(new_url, answer)
        print TextHelper.find_text_between_tag(new_web_content,
                                               '<font color="gold">',
                                               '</font>')
        mandelbrot_gif = TextHelper.find_text_between_tag(
            new_web_content, '<img src="', '" border="0">')
        mandelbrot_gif = WebHelper.join_url(new_url, mandelbrot_gif)
        print "Get new gif picture: %s" % mandelbrot_gif
        print TextHelper.find_text_between_tag(new_web_content,
                                               'border="0">\n', '\n	</img>')

        # step 2, parse mandelbrot gif
        left, top, width, height, iteration = 0.34, 0.57, 0.036, 0.027, 128
        img = ImageHelper.create_image_from_web(mandelbrot_gif, answer[0],
                                                answer[1])
        print "Get image size: %s, %s" % img.size
        w, h = img.size
        x_step, y_step = width / w, height / h
        result = []
        for y in range(h - 1, -1, -1):
            for x in range(w):
                c = complex(left + x * x_step, top + y * y_step)
                z = 0 + 0j
                for i in range(iteration):
                    z = z * z + c
                    if abs(z) > 2:
                        break
                result.append(i)
        new_img = img.copy()
        new_img.putdata(result)
        new_img.show()

        # step 3, show diff about these two picture
        diff = [(a - b) for a, b in zip(img.getdata(), new_img.getdata())
                if a != b]
        print len(diff)
        print set(diff)

        plot = Image.new('L', (23, 73))
        plot.putdata([(i < 16) and 255 or 0 for i in diff])
        plot.resize((230, 730)).show()
        prompt = 'arecibo'
        print "Oh, God dammit! Who knows this is a message humanity send to the starts from %s telescope" % prompt

        # step 4, set next challenge url
        next_level_url = WebHelper.join_url(mandelbrot_gif, prompt)
        next_level_url = WebHelper.change_suffix_url(next_level_url, 'html')
        self.set_next_level_url(next_level_url)