Pythonchallenge (iii)

Source: Internet
Author: User

Pythonchallenge_3

First, the experimental explanation

1. Environment Login

No password automatic login, system user name Shiyanlou, password Shiyanlou

2. Introduction to the Environment

This experiment environment uses the Ubuntu Linux environment with the desktop, the experiment will use the program on the desktop:

1. LX Terminal (lxterminal): Linux command line terminal, Open will enter the bash environment, you can use the Linux command
2. Firefox: Browser, can be used in the need for the front-end interface of the course, only need to open the environment to write the Html/js page can be
3. GVim: Very useful editor, the simplest usage can refer to the course [Vim editor]

3. Use of the environment

Use the Gvim editor to enter the code and files required for the experiment, and use the LX Terminal (lxterminal) to run the required commands.

After completing the experiment, you can click "Experiment" above the desktop to save and share the results to Weibo to show your friends the progress of your study. The lab building provides a back-end system that can prove to be true that you have completed the experiment.

The Experiment records page can be viewed in the My Home page, which contains each experiment and notes, as well as the effective learning time of each experiment (refers to the time of the experiment desktop operation, if there is no action, the system will be recorded as Daze time). These are the proof of authenticity of your studies.

Ii. introduction of the course

The ' Pythonchallenge ' series A total of 11 projects, continuous updating in ~ ~ ~, each project course will be explained in detail 3 ' pythonchallenge ' Customs clearance topics and different solutions, after-school exercises to decorate a task title, The topic will be unveiled in the next project.

This series of topics belong to the online problem, because the experimental building temporarily does not provide access to the network, so please verify the answer when trouble click your browser to visit the Web page to verify the answer.

All topics and reference solutions Copyright [Pythonchallenge Official website], curriculum preparation belongs to the experimental building original, welcome to ask questions actively in the question and answer area, small series will actively answer, also welcome in the comment area of the Spit Groove ~


Iii. Review of the experiment

In the previous [Project lesson], we learned a lot of knowledge, such as: Some functions in the ' re ' module, the use of the ' urllib ' module, and the function ' reduce '. The memory is not too bad you can still remember in the last course of the small and medium-sized have left everyone a lesson after homework, do not know how you finished?

Whether or not you get the answer, let the small part with you to solve the problem together!

Iv. Analysis of the work

# # # Problem: Please visit the [Challenge link] to view the source code and find a link to the next URL. (Hint: related to ' zip ')

* * Small brain hole: * *

First look at the source code:

After these several questions, we know that the general answer is hidden in the comments (' <!----> ' content). First, the first comment is the word ' zip ', the second note is slightly longer, roughly meaning: The following is not about the riddle itself, but I hope you can give a little funding for the project ' Pythonchallenge '. Then, the second comment has no effect. Look at the first note, there is only one word ' zip ', then the answer is ' zip ', so the modified link is: [http://www.pythonchallenge.com/pc/def/zip.html]. To get this result:

It means: "Zip" is found, then ' zip ' should be hidden in the source code:

Source does not give any information, then is not ' zip ' refers to the ' zip ' compression package it? Again back to modify the original link, the ' HTML ' into ' zip ', the result is really a compressed package, about this compression package, has been uploaded to the experimental building environment, so enter the following command to download the file and view the contents of the compressed package:

1 $ wget http://labfile.oss.aliyuncs.com/courses/411/channel.zip2 $ unzip-l channel.zip

The contents of the file are as follows:

A total of 910 files, most of the file name is digital type, unzip and view the description document ' readme.txt ':

12 $ VI readme.txt

Based on the above tips, we have learned two information:

    1. The loop starts with the ' 90052.txt ' file;
    2. The answer is hidden in the contents of the Zip archive folder.

View ' 90052.txt ' This document reads as follows:

Do you feel familiar when you see this sentence? Yes, in the last challenge, there was a sentence, the difference is that the last topic was to use the ' urllib ' module to find the keywords on the Web page, this time to find the answer in the compression package.

The algorithm is as follows:

    • 1. Set the starting point, enter the loop, and use regular expressions to match the numbers in the file contents;
    • 2. Use the number in the contents of the file as the next open file name;
    • 3. The loop condition is to find a file that does not end with a number and print the result
1 ImportRe2 3findnothing = Re.compile (r'Next Nothing Is (\d+)'). Match4 5  whileTrue:6FName = seed +'txt'7Text = open (fname,'R'). Read ()8m =findnothing (text)9     ifm:TenSeed = M.group (1) One     Else: A         Printtext -          Break

The printing results are as follows:

That means let's collect comments.

For comments, each file has its descriptive information, and you can view the description of the files in the package by entering a command:

1 unzip-l channel.zip

Give each file four information, such as the ' Reame.txt ' file, its annotated message is ' * ', the size of the file is ' 84 ' byte, the last modification time of the file is ' 2005-04-28 ', the file name is ' Readme.txt '. By connecting these comments, you can see if the results will tell us the information.

There is a module ' zipfile ' in ' Python ' that collects information about the compressed package, and the detailed documentation for that module is in [Official documents] (https://docs.python.org/2/library/zipfile.html).
There is a class in the module that we need to understand--' zipfile. ZipFile '. This module is mainly used to read and write files of type ' Zip '. The class has a function ' GetInfo (name) ' To return the file information named ' name ' in the compressed file, as this example needs to use the explanatory part inside the file information, so call ' ZipFile ' directly. Zipfile.getinfo (name). Comment ' can return a comment for the ' name ' file.

So modify the code as follows:

1 ImportZipFile, re2 3findnothing = Re.compile (r"Next Nothing Is (\d+)"). Match4comments = []#collect a list of comment information5z = zipfile. ZipFile ("Channel.zip","R")#To read a compressed package file6Seed ="90052"7 8  whileTrue:9FName = seed +". txt"Ten comments.append (Z.getinfo (fname). Comment) OneGuts =Z.read (fname) Am =findnothing (Guts) -     ifm: -Seed = M.group (1) the     Else: -          Break -     Print "". Join (comments)#Print all comment information

So the answer should be ' hockey ', go to the link:

Then let's look at the letters and suggest that the word refers to being in the air. The above-mentioned ' HOCKEY ' figure happens to consist of the letter ' O C Y G E N ', which is the word air-' oxygen '.

So came [next question].

V. Seventh challenging question

Question: Find the word that leads to the next link, based on this image.

* * Small brain hole: * *

However, this time the source code does not provide additional information, then can only look at the picture, careful observation, found that the picture is not complete, the middle of the picture is a different depth of gray bar to cover up, then the information is likely to be hidden in the face. So in image processing we know that each image is made up of countless pixel values, which is actually a matrix of [pixels], and the answer is probably related to these pixel values. For specific ideas on this issue, interested friends can take a look at my [blog].

First, download the ' image ' module for processing the image, and then download the image ' Oxygen.png ' that the subject needs to process.

1 $ sudo apt-get install python-imaging2 $ wget http://labfile.oss.aliyuncs.com/courses/411 /oxygen.png


Enter the following code to observe the size of the picture:

1 Import Image 2 img = image.open ('oxygen.png'3 img.size

The result of the return of ' img.size ' shows that the pixels in the horizontal and vertical directions of the image are ' 629 ' and ' 95 ' respectively; the coordinates of this mosaic area can be extracted using the drawing tool:

The horizontal axis range is: ' 0-609 ', the Ordinate range is: ' 43-53 '.

Then use the function ' GetPixel ' inside the ' Image ' module to get the pixel data for this area:

1 # List-expression 2  for inch  for  in range (+)]3print data

Looking at the printed results, you will find that the output pixel list is a ' 4 ' tuple, where the first three elements of the tuple correspond to the corresponding ' RGB ' component: ' R ', ' G ', ' B ', and because the gray satisfies the condition is ' r=g=b ', and the tuple is observed to repeat 7 changes at a time, So how do you relate these output results to your answers?

In general, the answer links are English letters, then you can try to convert these values into the function ' CHR ' to translate these ' ASCII code ' into the corresponding English letters.

1 # Select all pixel information for the printed line 45 first 2  for  in range (0, 609, 7)]3"". Join (ROW)

The meaning of the sentence is ' [105,110,116,101,103,114,,105,116,121] '. Say, convert these ASCII codes to letters and concatenate them into strings:

The word leading to the next level is ' integrity ', so go to the next level [link].

VII. Eighth Challenge question

Problem: Find the missing link

* * Small brain hole: * *

Find the missing link? Then the clearance port should not be a simple word substitution but a hyperlink to see if the source code has the information we need:

We notice that in ' center/img ' there is an attribute ' usemap ' as ' notisect ', and the description of ' Notisect ' is described under ' \map\area ', which means that this is the link in the ' interity ' diagram, about ' The content of Coords ' is an area of the picture, which points to a link ' @href = '. /return/good/html ' Click on the image to pop up the following dialog (more about the ' Usemap ' attribute of the ' img ' tab, see [Documentation]):

This means that we need to find the user name and password in the original page to log in to this authentication.

Once again, observe the comment section in the source code and discover:

If the string following the ' UN ' (username) is interpreted as a user name, then the string in ' PW ' (password) is the password.

So how should these strings be decoded? Carefully observe the composition of the string, whether the user name or password is the ' BZ ' string, and later learned that ' BZ ' string is actually a ' bz2 ' compressed format, then how to extract it? First import the module and then enter ' dir (bz2) ' to see the functions of the ' bz2 ' module:

' Compress ' is a ' compression ' function, then ' decompress ' is the decompression function, continue to see the function usage:

Because we have fewer strings, we can use the function ' decompress ' to extract data:

1 Import bz2 2 "' bzh91ay&sya\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3m\x07<]\xc9\x14\xe1ba\x06\xbe\x084 ' 3 ' bzh91ay&sy\x94$|\x0e\x00\x00\x00\x81\x00\x03$ \x00!\x9ah3m\x13<]\xc9\x14\xe1bbp\x91\xf08'  4bz2.decompress (un)5 bz2.decompress (PW)

Get the user named ' huge ', the password is ' file ', in fact, this problem is very simple, as long as the understanding of the ' BZ ' format of the string is a form of compression, and then the corresponding decompression can solve the problem.

Viii. Mission

Question: Please link up the points, [topic links] (Hint: source code, source code!) )。

Pythonchallenge (iii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.