[Clearance] Python challenge codes and Raiders (0-7)

Preface:

Recently I found a game about python break through the barrier, which is the game of thinking and clearance Raiders

Initially located: http://www.pythonchallenge.com/pc/def/0.html

0 Off

Topic analysis

Tip hint tell us is to try to change the URL address, the figure is 2 ^ 38, the address is the result of speculation.

Examine knowledge

  • This is only the beginning, suggesting how we pass through the site, as well as in the int python learned never overflow, there is a mechanism for automatic expansion.

Code and results

print(2**38)

Output: 274877906944

Next Level: http://www.pythonchallenge.com/pc/def/274877906944.html

1st Off

Topic analysis

Alternatively noted letters, and K, M, E 2 is moved back from the alphabet. Learned will know that that is the Caesar cipher.

Initially I use the online hack site. After the break, found that can be used string.maketrans () to solve, first create a mapping table with maketrans, and then use the translate function

Examine knowledge

  • String handling, involving string library

Of course, you can not string, use [chr(i) for i in range(97,122)]to produce the letters az.

Code and results

import string
src = 'g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr\'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.'

for i in range(1,26):
    mapping = ''.maketrans(string.ascii_lowercase,string.ascii_lowercase[i:]+string.ascii_lowercase[:i])
    print(src.translate(mapping))

输出:i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url.

This means that is the map-> ocr
Next Level: http://www.pythonchallenge.com/pc/def/ocr.html

2 off

Topic analysis

Notes that information lower left is to tell you how to check out the official answer on a off.

According red prompt text, access to information: identifying characters in the book may be, may in page source (web page source code) in

F12 to view the source code, you can see see the information in the body> font> font in

find rare characters in the mess below, that is, to do data cleansing

The need to clean the contents copied into the file 'src / ocr.txt' I this is a relative path, you can easily set up, as long as he can open it

Examine knowledge

  • Simple data cleansing, involving re library

Code and results

import re

with open('src/ocr.txt','r') as f:
    s = f.read()
rs = re.findall(r'[a-zA-Z0-9]+',s)
print(''.join(rs))

Output: equality

Next Level: http://www.pythonchallenge.com/pc/def/equality.html

3 Off

Topic analysis

F12 to view source code, see the body> font:

Examine knowledge

  • Simple data cleansing, similar to the previous question involves re library
  • Noted hint, a lowercase letter, precisely the presence of three capital letters on both sides, that is xXXXxXXXx form, taking only a middle lower case letters.

You can also use source web crawling request. I saved in 'src / equality.txt' in

Code and results

import re
with open('src/equality.txt','r') as f:
    s = f.read()
rs = re.findall(r'[a-z][A-Z]{3}([a-z])[A-Z]{3}[a-z]',s,re.S)
print(''.join(rs))

Output: linkedlist

Next Level: http://www.pythonchallenge.com/pc/def/linkedlist.html

4 Off

Topic analysis

  • Only simple text pages, linkedlist.php, it is natural to enter the url jump

  • F12 page title is: follow the chain, may also prompt us to urllib help, and probably to cycle 400 times, found a suspicious link below to open the link: a number appears, such as inter-related chain, I used the requests crawling, web pages should be simple and only one number, so we do not resolve

Examine knowledge

  • requests or other crawling library, re

Code and results

import requests,re

def get_src(url):
    respon = requests.get(url)
    if respon.status_code == 200:
        return re.findall(r'\d+',str(respon.content))[0]
     
url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing='
add = '12345'
count = 0
for i in range(400):
    count += 1
    add = get_src(url+add)
    print(f'{count}:{add}',end = ' ')

After an exception, since I can add to modify.

Output:
Department 16044 anomaly:. Yes Divide by two and keep going.

82683处异常:You've been misleaded to here. Go to previous one and check.

82682处异常:There maybe misleading numbers in the text. One example is 82683. Look only for the next nothing and the next nothing is 63579

66831 anomaly: peak.html, in fact, is the next level

Next Level: http://www.pythonchallenge.com/pc/def/peak.html

Level 5

Topic analysis

  • pronounce it, read it straight turn, F12 found:

banner.p suspicious, open

Scared garbled, after learning Baidu found to use the pickle module --python object serialization
save file suffix .p

报错:TypeError: a bytes-like object is required, not 'str'

Explanation: Since the current operation is a string of bytes string object type, and follow this string object type str bytes type

Solution: Open (File, 'RB')
the pickle.load (File) can decode a list of two

Is really a ghost, the beginning I did not think this is a character pattern. . . . . .

Finally come: the list is a tuple, (character, number), analyze the data, it is easy to get an answer after qwq come to resolve channel

Examine knowledge

  • The pickle python library

Code and results

import pickle

with open('src/banner.p','rb') as f: 
    data = pickle.load(f)

s = ''
for i in data:
    for j in i:
        s += j[0]*j[1]
    s+='\n'
print(s)

Output:

Next Level: http://www.pythonchallenge.com/pc/def/channel.html

Level 6

Topic analysis

  • Hey, there's a pay, sometimes this plan will crack, the rich. . . .
  • F12 View source discovery

    that is the existence of a zip file, download the file.
    I was after the first two stages are not using zipfile.

  • Notes need to collect the compressed file = _ = #, after a wave of exciting action, I know you can get a comment by comment zipfile module z.getinfo ( '90052.txt').

Finally collect notes, pay attention to coding issues, open only r / w,

Examine knowledge

  • Document processing, zizpfile library

Code and results

import zipfile,re

z = zipfile.ZipFile('src/channel.zip')

val = '90052'
count = 0
s = []
try:
    while True:
        count += 1
        print(f'{count}:{val}')
        file = f'{val}.txt'
        with z.open(file,'r') as f:
            s.append(z.getinfo(file).comment)
            text = str(f.read(), encoding='UTF-8')
        val = re.findall(r'\d+',text)[-1]
except:
    s.append(z.getinfo(f'{val}.txt').comment)
    print(val)
    d = ''
    for i in s:
        d += str(i,encoding = 'utf-8')

    print(d)

Output:

Next Level: http://www.pythonchallenge.com/pc/def/hockey.html

7 Off

Topic analysis

  • I really do not understand what this means, F12 source code, request resources, not information. Finally, after carefully reading these words, ha ha ha. TM oxygen oxygen, forced to explain look air. . . . .

Examine knowledge

  • Brain-dong? ghost

    Code and results

Output: oxygen

Next Level: http://www.pythonchallenge.com/pc/def/oxygen.html

And there are many, many levels, subsequent updates. . . . . .

Guess you like

Origin www.cnblogs.com/yanshanbei/p/12470787.html