示例#1
0
    def do_compute(self):
        # step 1, get prompt form web source
        email_string = TextHelper.find_text_between_tag(self.web_source, "<!--\n", "\n-->")
        message = email.message_from_string(email_string)
        audio = message.get_payload(0).get_payload(decode=True)
        local_wav = "mainland.wav"
        WaveHelper.save_base64_file(audio, local_wav)
        WaveHelper.play(local_wav)  # pronounce 'sorry'
        pronounce_word = "sorry"
        print "pronounce word: %s" % pronounce_word

        # step 2, wrong try
        sorry_url = WebHelper.join_url(self.url, pronounce_word)
        url_ignore, sorry_content = WebHelper.get_auth_url_content(sorry_url, self.user, self.password)
        print sorry_content

        # step 3, reverse the wav data
        reverse_wave = "sea.wav"
        WaveHelper.reverse_wave(local_wav, reverse_wave)
        WaveHelper.play(reverse_wave)  # pronounce "you are idiot, a.a.a.a..."
        print "pronounce word: %s" % "you are idiot, a.a.a.a..."
        prompt_url = WebHelper.join_url(self.url, "idiot")
        print "prompt url: %s" % prompt_url

        # step 4, get next level url
        next_url = WebHelper.get_prompt_url_from_web(prompt_url, '<br><a href="', '">Continue to the', self.user,
                                                     self.password)
        self.set_next_level_url(next_url)

        # step 5, clean resources
        FileHelper.remove_file(local_wav)
        FileHelper.remove_file(reverse_wave)
示例#2
0
    def do_compute(self):
        # step 1, get prompt information from web source
        words_hint = TextHelper.find_text_between_tag(self.web_source, "<!-- ", " -->")
        print words_hint
        img_url_short = TextHelper.find_text_between_tag(self.web_source, "<img src=\"", "\" border=")
        ImageHelper.show_image_from_web(WebHelper.join_url(self.url, img_url_short))
        # It shows a same picture with different brightness
        print "brightness"
        prompt_url = WebHelper.join_url(self.url, "brightness")
        print "get new prompt url: %s" % prompt_url

        # step 2, download gz file from web
        prompt_url = WebHelper.get_prompt_url_from_web(prompt_url, "<!-- maybe consider ", " -->")
        local_gz = WebHelper.get_url_page(prompt_url)
        WebHelper.download_with_auth(prompt_url, local_gz)

        # step 3, get png data and show the image
        gz_content = FileHelper.read_gzip_file(local_gz)
        png = T18.get_png_data_from_diff_data(gz_content)

        for i in range(3):
            ImageHelper.show_image_from_data(png[i])

        # from image, we can see "../hex/bin.html", "butter", "fly"  ==> These last two words will be used in next level
        prompt_url = "../hex/bin.html"
        print 'we can see "../hex/bin.html", "butter", "fly" in these image, set new user, password for next level'
        self.result.set_user_password("butter", "fly")

        # step 4, set prompt
        self.set_prompt(prompt_url)

        # step 5, clean zip file
        FileHelper.remove_file(local_gz)
示例#3
0
    def do_compute(self):
        # step 1. get prompt information from web source
        words_prompt = TextHelper.find_text_between_tag(
            self.web_source, "<!-- ", "-->")
        print words_prompt  # remember: 100*100 = (100+99+99+98) + (...

        url_prompt = TextHelper.find_text_between_tag(
            self.web_source, "<img src=\"", "\" width=\"100\" height=\"100\">")
        img_url = WebHelper.join_url(self.url, url_prompt)
        print "get image url: " + img_url
        url_ignore, img_data = WebHelper.get_auth_url_content(img_url)

        # step 2. try to get information from img
        wire_img = Image.open(StringIO(img_data))
        (width, height) = wire_img.size
        print width, height  # The picture size is '10000, 1' ===> 10000 = 100 * 100

        # step 3. draw picture in square
        T14.draw_circle(wire_img)  # We can see the picture is cat

        # step 4. cat url
        cat_url = WebHelper.join_url(self.url, "cat")
        url_ignore, cat_content = WebHelper.get_auth_url_content(cat_url)
        cat_prompt = TextHelper.find_text_between_tag(
            cat_content, "and its name is <b>", "</b>. you'll hear from him ")

        # step 5. set prompt for the next level
        self.set_prompt(cat_prompt)
示例#4
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)
示例#5
0
    def do_compute(self):
        # step 1, get picture from web source
        prompt_url = TextHelper.find_text_between_tag(self.web_source, "<img src=\"", "\" border=\"0\"/>")
        cookie_img_url = WebHelper.join_url(self.url, prompt_url)
        ImageHelper.show_image_from_web(cookie_img_url)  # Do you feel familiar with the embed picture? Yes, the level 4
        level_4_start_url, ignore_content = WebHelper.get_final_url_content("http://www.pythonchallenge.com/pc/def/linkedlist.html")
        print "python challenge level 4 start url: " + level_4_start_url

        # step 2, get traverse start url
        cookies, level_4_web_source = WebHelper.get_cookie_content_from_url(level_4_start_url)
        cookie_prompt = ''.join(cookies)  # you+should+have+followed+busynothing...
        print "prompt from start web cookie: " + cookie_prompt
        new_para = TextHelper.find_text_between_tag(cookie_prompt, "have followed ", "...")
        print "get new para from cookie prompt: " + new_para
        origin_start_url = TextHelper.find_text_between_tag(level_4_web_source, "<center>\n<a href=\"", "\">")
        print "get origin start url: " + origin_start_url
        start_url = WebHelper.join_url(level_4_start_url, origin_start_url.replace("nothing", new_para))
        print "replace with new para, get final start url: " + start_url

        # step 3, get traverse start url
        cookies_collect = WebHelper.get_traverse_cookie(start_url, "and the next busynothing is ")
        compressed_message =  ''.join(cookies_collect)
        print "Get compressed message from cookies: " + compressed_message

        # step 4, uncompress message
        message = bz2.decompress(compressed_message)
        print "decompressed messsage: %s" % message
        # decompressed messsage: is it the 26th already? call his father and inform him that "the flowers are \
        # on their way". he'll understand.
        his_father = "Leopold"
        message = TextHelper.find_text_between_tag(message, "call his father and inform him that \"", "\". he'll ")

        # step 5, call his father
        his_father = "Leopold"
        phone_book_url = "http://www.pythonchallenge.com/pc/phonebook.php"
        phone = xmlrpclib.ServerProxy(phone_book_url)
        number = phone.phone(his_father)
        print "%s number is %s" % (his_father, number)  # Leopold number is 555-VIOLIN
        ignore_url, violin_content = WebHelper.get_auth_url_content(WebHelper.join_url(self.url, "violin"))
        print violin_content
        violin_url = TextHelper.find_pattern_in_content(violin_content, "no! i mean yes! but (.*php)")[0]
        print "violin url is %s" % violin_url
        leopold_url = WebHelper.join_url(self.url, violin_url)

        # step 6, send the message
        opener = urllib2.build_opener()
        message = "the flowers are on their way"
        opener.addheaders.append(('Cookie', 'info=' + quote_plus(message)))
        response = opener.open(leopold_url)
        leopold_prompt = response.read()

        # step 7, set next level prompt
        final_prompt = TextHelper.find_text_between_tag(leopold_prompt, "t you dare to forget the ", ".</font>")
        self.set_prompt(final_prompt)
示例#6
0
    def do_compute(self):
        # step 1, get prompt information from web source
        print TextHelper.find_text_between_tag(self.web_source, '<!-- ', '-->')
        wav_suffix = 'wav'
        print "Above prompt words ask us to replace the suffix of jpg to %s" % wav_suffix
        wave_img_url = WebHelper.join_url(
            self.url,
            TextHelper.find_text_between_tag(self.web_source, '<img src="',
                                             '">'))
        print "wave image web url is %s" % wave_img_url
        ImageHelper.show_image_from_web(
            WebHelper.join_url(self.url, wave_img_url), self.user,
            self.password)
        print "This picture prompt us: there is 25 block, we need to combine them"

        # step 2, download waves
        wave_url = WebHelper.change_suffix_url(wave_img_url, wav_suffix)
        print "After change suffix: %s" % wave_url
        local_directory = 't25'
        FileHelper.mkdir(local_directory)
        waves = []
        for i in range(25):
            store_path = FileHelper.join_path(local_directory,
                                              WebHelper.get_url_page(wave_url))
            WebHelper.download_with_auth(wave_url, store_path, self.user,
                                         self.password)
            waves.append(wave.open(store_path))
            wave_url = WebHelper.url_add(wave_url)

        # step 3, Create combine image from waves
        img = Image.new('RGB', (300, 300), 'black')
        frames = waves[0].getnframes()
        print "Totally waves: %d" % len(waves)
        for i in range(len(waves)):
            tmp_img = Image.frombytes('RGB', (60, 60),
                                      waves[i].readframes(frames))
            current_pos = (60 * (i % 5), 60 * (i // 5))
            print "Put image to position%s" % str(current_pos)
            img.paste(tmp_img, current_pos)
        img.show()  # It shows a words 'decent'

        # step 4, set prompt words
        prompt_word = 'decent'
        print "Get prompt words from combined picture: %s" % prompt_word
        self.set_prompt(prompt_word)

        # step 5, clean unused file
        FileHelper.remove_folder(local_directory)
示例#7
0
    def do_compute(self):
        # step 1, get information from web source
        print TextHelper.find_text_between_tag(self.web_source, '	<!-- ',
                                               '-->')
        print TextHelper.find_text_between_tag(self.web_source,
                                               '<font color="gold">\n',
                                               '\n        </font>')
        warm_up_url = TextHelper.find_text_between_tag(self.web_source,
                                                       'blanks <!-- for ',
                                                       ' -->')
        warm_up_url = WebHelper.join_url(self.url, warm_up_url)

        # step 2, solve first etch-a-scetch
        file_content = WebHelper.get_auth_url_content(warm_up_url, self.user,
                                                      self.password)[1]
        # print "Words in warmup.txt:\n%s" % file_content
        # sketch = Sketch(file_content)
        # sketch.play_game()
        Sketch.play_game(file_content)
        prompt = 'up'
        print "It shows an %s tag" % prompt
        second_file = WebHelper.join_url(warm_up_url, prompt)

        # step 3, solve the second etch-a-scetch
        file_content = WebHelper.get_auth_url_content(second_file, self.user,
                                                      self.password)[1]
        # sketch = Sketch(file_content)
        # sketch.play_game()
        Sketch.play_game(file_content)
        python = 'python'
        print "It shows a picture of %s" % python

        # step 4, search the wiki get prompt information
        python_url = WebHelper.join_url(self.url, python)
        print "Python url: %s" % python_url
        file_content = WebHelper.get_auth_web_source(python_url, self.user,
                                                     self.password)
        print TextHelper.find_text_between_tag(file_content,
                                               '<font color="gold">',
                                               '</font>')
        prompt = 'beer'
        print "Search on the wiki %s is the words next to Free" % prompt

        # step 5, set prompt for next url
        self.set_prompt(prompt)
示例#8
0
    def do_compute(self):
        # step 1. get hint from web source
        prompt_url = TextHelper.find_text_between_tag(
            self.web_source, "coords=\"326,177,45\" href=\"", "\" />")
        phone_book_url = WebHelper.join_url(self.url, prompt_url)

        # step 2. use xmlrpclib
        server = xmlrpclib.Server(phone_book_url)
        print server.phone('Bert')  # print 555-ITALY

        # step 3. set prompt
        self.set_prompt('italy')
示例#9
0
    def do_compute(self):
        # step 1. Get hint from page source
        hint = TextHelper.find_text_between_tag(self.web_source,
                                                "<html> <!-- <-- ",
                                                " -->\n<head>")
        zip_url = WebHelper.change_suffix_url(self.url, hint)

        # step 2. Download zip to local and extract
        tmp_zip = zip_url[zip_url.rindex("/") + 1:]
        tmp_folder = tmp_zip[:tmp_zip.index(".")]
        WebHelper.download(zip_url, tmp_zip)
        zip_ref = zipfile.ZipFile(tmp_zip, 'r')
        zip_ref.extractall(tmp_folder)
        zip_ref.close()

        # step 3. Get next hint
        readme_txt = open(tmp_folder + "/readme.txt", 'r').read()
        start_txt = TextHelper.find_text_between_tag(readme_txt,
                                                     "hint1: start from ",
                                                     "\n")
        next_hint = T6.read_traverse(start_txt)
        print next_hint  # Hint: Collect the comments.

        # step 4. Get comments
        print T6.collect_comments(
            tmp_zip, start_txt)  # Comments: HOCKEY  (Small letter oxygen)

        # step 5. Wrong way
        wrong_url = WebHelper.join_url(self.url, "hockey")
        print WebHelper.get_web_source(
            wrong_url)  # it's in the air. look at the letters.

        # step 6. Get next url hint
        self.set_prompt(WebHelper.join_url(self.url, "oxygen"))

        # step 7. Clean folder
        FileHelper.remove_folder(tmp_folder)
        FileHelper.remove_file(tmp_zip)
示例#10
0
    def do_compute(self):
        # step 1. get prompt from web source       hint: len(a[30]) = ?
        prompt_url = TextHelper.find_text_between_tag(self.web_source,
                                                      "href=\"", "\" />")
        sequence = WebHelper.get_auth_web_source(
            WebHelper.join_url(self.url, prompt_url))
        print sequence  # a = [1, 11, 21, 1211, 111221,

        # step 2. compute len(a[30])
        a_str = '1'
        for i in range(30):
            a_str = T10.read_string(a_str)

        # step 3. set prompt
        self.set_prompt(str(len(a_str)))
示例#11
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)
示例#12
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())
示例#13
0
    def do_compute(self):
        # step 1. get information from url
        login_url_prompt = TextHelper.find_text_between_tag(
            self.web_source, "href=\"", "\" />")
        login_url = WebHelper.join_url(self.url, login_url_prompt)
        user_encode = TextHelper.find_text_between_tag(self.web_source,
                                                       "un: '", "'")
        user = bz2.decompress(user_encode.decode('string_escape'))
        print "user = "******"pw: '", "'")
        password = bz2.decompress(password_encode.decode('string_escape'))
        print "password = " + password  # file
        self.result.set_user_password(user, password)

        # step 2. Login with user, password
        self.set_next_level_url(login_url)
示例#14
0
    def do_compute(self):
        # step 1. Get banner dump data
        banner_prompt = TextHelper.find_text_between_tag(
            self.web_source, "peakhell src=\"", "\"/>")
        banner_url = WebHelper.join_url(self.url, banner_prompt)
        banner_data = WebHelper.get_web_source(banner_url)

        # step 2. show the banner
        banner = ''
        for line in pickle.loads(banner_data):
            for char, count in line:
                banner += char * count
            banner += '\n'
        print banner  # Get word channel

        # step 3. Set prompt
        self.set_prompt("channel")
示例#15
0
    def do_compute(self):
        # step 1. Get traverse start url
        start_url_prompt = TextHelper.find_text_between_tag(
            self.web_source, "<center>\n<a href=\"", "\">")
        start_url = WebHelper.join_url(self.url, start_url_prompt)
        print "Get start traverse url" + start_url
        # start url is http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345

        # step 2. Traverse in url, util the end url
        end_url, end_content = WebHelper.get_traverse_url_content(
            start_url, "and the next nothing is ")
        # end url is http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=66831

        # step 3. Get the next level url
        final_url, final_content = WebHelper.get_final_url_content(
            end_url, end_content)
        self.set_next_level_url(final_url)
示例#16
0
    def do_compute(self):
        # step 1. get prompt information
        prompt_img_url = TextHelper.find_text_between_tag(self.web_source, "<img src=\"", "\"><br>")
        img_url = T12.evil_add_url(WebHelper.join_url(self.url, prompt_img_url))
        print "get new image url: " + img_url
        url_ignore, img_data = WebHelper.get_auth_url_content(img_url)
        img = Image.open(StringIO(img_data))
        img.show()  # shows: we should use suffix .gfx not .jpg

        # step 2. get gfx file
        gfx_url = WebHelper.change_suffix_url(img_url, ".gfx")
        url_ignore, gfx_data = WebHelper.get_auth_url_content(gfx_url)

        # step 3. play data cards
        T12.play_cards(gfx_data)  # There were five picture shows : 'dis', 'pro', 'port', 'ional', 'ity' (strikeout)

        # step 3. set prompt for next level
        self.set_prompt('disproportional')
示例#17
0
    def do_compute(self):
        # step 1. get png url and download
        png_prompt = TextHelper.find_text_between_tag(self.web_source, "<img src=\"", "\"/>")
        png_url = WebHelper.join_url(self.url, png_prompt)
        png_local = WebHelper.get_url_page(png_url)
        WebHelper.download(png_url, png_local)

        # step 2. get prompt information
        png = Image.open(png_local)
        row = [png.getpixel((x, png.size[1]/2)) for x in range(0, png.size[0], 7)]
        print ''.join([chr(r) for r, g, b, d in row if r == g and g == b])
        # get hint: smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]

        # step 3. set prompt for next url
        self.set_prompt(''.join([chr(i) for i in [105, 110, 116, 101, 103, 114, 105, 116, 121]]))

        # step . clean file
        FileHelper.remove_file(png_local)
示例#18
0
    def do_compute(self):
        # step 1, get prompt information from web source
        gif_prompt = TextHelper.find_text_between_tag(self.web_source,
                                                      '<!-- or maybe ',
                                                      ' would be more')
        gif_url = WebHelper.join_url(self.url, gif_prompt)
        print "Get gif url: %s" % gif_url

        ImageHelper.show_image_from_web(gif_url, self.user, self.password)
        local_image = WebHelper.get_url_page(gif_url)
        WebHelper.download_with_auth(gif_url, local_image, self.user,
                                     self.password)
        ImageHelper.show_from_file(local_image)

        # step 2, get Image draw
        img = Image.open(local_image)
        prompt_img = Image.new("RGB", (500, 200))
        draw = ImageDraw.Draw(prompt_img)
        cx, cy = 0, 100
        for frame in range(img.n_frames):
            img.seek(frame)
            left, upper, right, lower = img.getbbox()
            dx = left - 100
            dy = upper - 100

            if dx == dy == 0:
                cx += 50
                cy = 100

            cx += dx
            cy += dy

            draw.point([cx, cy])
        prompt_img.show()  # shows 'bonus'

        # step 3, set prompt
        prompt_words = 'bonus'
        print "get prompt words from image %s" % prompt_words
        self.set_prompt(prompt_words)

        # step 4, clean unused files
        FileHelper.remove_file(local_image)
示例#19
0
    def do_compute(self):
        # step 1, get question from web source
        words_prompt = TextHelper.find_text_between_tag(
            self.web_source, "<title>", "</title>")
        print words_prompt  # ask us who is this person?

        # step 2, get image from web
        prompt_url = TextHelper.find_text_between_tag(self.web_source,
                                                      "<img src=\"", "\"><br>")
        img_url = WebHelper.join_url(self.url, prompt_url)
        url_ignore, img_data = WebHelper.get_auth_url_content(img_url)
        ImageHelper.show_image_from_web(
            img_url)  # a calendar shows a date January, 26, 1XX6
        month = 1
        day = 26

        # step 3, calculate possible date
        possible_year = filter(lambda y: isleap(y) and 0 == weekday(y, 1, 26),
                               range(1006, 2000, 10))
        print possible_year

        # step 4, get the date with more prompt information
        words_prompt = TextHelper.find_text_between_tag(
            self.web_source, "<!-- todo: ", " -->")
        print words_prompt  # prompt us the date after January, 26 is some day special for memory
        day += 1

        words_prompt = TextHelper.find_text_between_tag(
            self.web_source, "<center>\n<!-- ", " -->")
        print words_prompt  # prompt us choose the second youngest
        year = possible_year[-2]

        print "The day special for flower is " + str(year) + "/" + str(
            month) + "/" + str(day)
        # some body may know but I don't know this day is the birthday of mozart
        # https://en.wikipedia.org/wiki/January_27#Births

        # step 5, set prompt for the next leve
        self.set_prompt("mozart")
示例#20
0
    def do_compute(self):
        # step 1, get image link from web source
        img_prompt = TextHelper.find_text_between_tag(self.web_source, "<img src=\"", "\"><br>")
        img_url = WebHelper.join_url(self.url, img_prompt)
        url_ignore, img_data = WebHelper.get_auth_url_content(img_url)
        img = Image.open(StringIO(img_data))
        img.show()
        width, height = img.size
        print width, height

        # step 2, strength the line
        new_img = Image.new('RGB', (width, height), 'black')
        for h in range(height):
            line = [img.getpixel((w, h)) for w in range(width)]
            pink = line.index(195)
            line = line[pink:] + line[:pink]
            for w, pixel in enumerate(line):
                new_img.putpixel((w, h), pixel)
        new_img.show()  # picture with words: romance

        # step 3, set prompt
        self.set_prompt("romance")
示例#21
0
    def do_compute(self):
        # step 1. get picture from web
        prompt_img_url = TextHelper.find_text_between_tag(
            self.web_source, "<img src=\"", "\" width=\"640\" height")
        img_url = WebHelper.join_url(self.url, prompt_img_url)
        local_img = WebHelper.get_url_page(img_url)
        WebHelper.download_with_auth(img_url, local_img)

        # step 2. get odd picture
        img = Image.open(local_img)
        odd = Image.new(img.mode, (img.size[0], img.size[1]))
        for x in range(img.size[0]):
            for y in range(img.size[1]):
                if (x + y) % 2 == 0:
                    odd.putpixel((x, y), img.getpixel((x, y)))
        odd.show()  # shows: 11 evil
        odd.close()

        # step 3. set prompt
        self.set_prompt("evil")

        # step 4. clear the files
        FileHelper.remove_file(local_img)
示例#22
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)
示例#23
0
    def do_compute(self):
        # step 1, get prompt information from web source
        unreal_img_url = WebHelper.join_url(
            self.url,
            TextHelper.find_text_between_tag(self.web_source, "<img src=\"",
                                             "\" border="))
        print "Get image url: %s" % unreal_img_url
        response = requests.get(unreal_img_url,
                                auth=HTTPBasicAuth(self.user, self.password))
        print "Headers: %s" % response.headers

        # step 2, loop to get more information
        response = self.loop_next_range(unreal_img_url, response.headers)
        # Information: Why don't you respect my privacy?
        response = self.loop_next_range(unreal_img_url, response.headers)
        # Information: we can go on in this way for really long time.
        response = self.loop_next_range(unreal_img_url, response.headers)
        # Information: stop this!
        response = self.loop_next_range(unreal_img_url, response.headers)
        # Information: invader! invader!
        response = self.loop_next_range(unreal_img_url, response.headers)
        # Information: ok, invader. you are inside now.
        (start, end,
         length) = self.get_content_range(response.headers['content-range'])
        invader_prompt = TextHelper.find_text_between_tag(
            response.content, 'ok, ', '. you are inside now.')
        invader_url = WebHelper.join_url(self.url, invader_prompt)
        print "Get invader url : %s" % invader_url
        response = self.loop_next_range(invader_url)
        # Information: Yes! that's you!

        # step 3, try cross the border
        response = requests.get(
            unreal_img_url,
            headers={'Range': 'bytes=%i-' % (int(length) + 1)},
            auth=(self.user, self.password))
        (start, end,
         length) = self.get_content_range(response.headers['content-range'])
        print "Headers: %s" % response.headers
        print "Information: %s" % response.content  # esrever ni emankcin wen ruoy si drowssap eht

        content_reverse = response.content.strip()[::-1]
        print "reverse content: %s" % content_reverse  # the password is your new nickname in reverse
        invader_password = invader_prompt[::-1]
        print "invader password is %s" % invader_password

        response = requests.get(
            unreal_img_url,
            headers={'Range': 'bytes=%i-' % (int(start) - 1)},
            auth=(self.user, self.password))
        print "Headers: %s" % response.headers
        print "Information: %s" % response.content  # 'and it is hiding at 1152983631.\n'

        prompt_start = TextHelper.find_text_between_tag(
            response.content, 'it is hiding at ', '.\n')
        response = requests.get(
            unreal_img_url,
            headers={'Range': 'bytes=%i-' % (int(prompt_start))},
            auth=(self.user, self.password))
        local_zip_file = 'invader.zip'
        FileHelper.save_to_zip_file(response.content, local_zip_file)

        # step 4, unzip local zip file
        FileHelper.unzip_file_with_password(local_zip_file, invader_password)

        # step 5, clean unused file
        FileHelper.remove_file(local_zip_file)

        # step 6, set next used file
        self.result.set_file('package.pack')
示例#24
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)
示例#25
0
 def evil_add_url(img_url):
     page = WebHelper.get_url_page(img_url)
     page_add = page[:4] + str(int(page[4: page.index(".")]) + 1) + page[page.index("."):]
     return WebHelper.join_url(img_url, page_add)