关卡地址

解决方案:

思路:

图片下有句提示信息:

pronounce it

查看源代码得到如下提示:

peak hell sounds familiar ?

听着一点也不熟悉好吧😂!无奈找了其他攻略,原来说的是python的pickle库,一个数据持久化库。

既然是要使用pickle库,肯定还需要额外的文件。查看源代码,在peakhell标签找到了一个banner.p文件。

使用pickle反序列化后,得到的是一个二维列表,元素是一个元组,表示(char,number)

最终得到的字符画如下:

channel

PS:如果看不出字符画是什么,请增加窗口显示宽度试试。

代码:

Challenge005.py

banner="http://www.pythonchallenge.com/pc/def/banner.p"

dir=".\\Data\\005"
import helper
helper.ensureDir(dir)

import urllib.request
(filename,headers)=urllib.request.urlretrieve(banner,dir+'\\banner.p')

import pickle
data=pickle.Unpickler(open(filename,'rb')).load()

# print(data)


for line in data:
    for tupleitem in line:
        print(tupleitem[0]*tupleitem[1],end='')
    print('')

# ================================

# without pickle

fp=open(filename,'r')
lines=fp.readlines()
fp.close()

import re
reln=re.compile('aa')
renum=re.compile('^I([0-9]*)')
rechsharp=re.compile("S'#'|g6")
rechspace=re.compile("S' '|g2")

for line in lines:
    if reln.search(line) != None:
        print('\n',end='')
        continue
    if rechsharp.search(line) != None:
        ch='#'
        continue
    if rechspace.search(line) != None:
        ch=' '
        continue
    if renum.search(line) != None:
        num=renum.search(line).group(1)
        print(ch*int(num),end='')
        continue
# ================================
PS src\static> python .\Code\Python\Challenge005.py

Challenge005.ps1

$banner="http://www.pythonchallenge.com/pc/def/banner.p"

$path=".\\Data\\005"

. .\Code\PowerShell\helper.ps1
New-Dir -Dir $path

$filename=$path+"\\banner.p"
Invoke-WebRequest -Uri $banner -OutFile $filename

$lines=Get-Content $filename

$reln=[regex]'aa'
$renum=[regex]'^I([0-9]*)'
$rechsharp=[regex]"S'#'|g6"
$rechspace=[regex]"S' '|g2"

foreach ($line in $lines) {
    if ($reln.IsMatch($line)) {
        [System.Console]::WriteLine()
        continue
    }
    if ($rechsharp.IsMatch($line)) {
        $ch='#'
        continue
    }
    if ($rechspace.IsMatch($line)) {
        $ch=' '
        continue
    }
    if ($renum.IsMatch($line)) {
        $num=[int]$renum.Match($line).Groups[1].Value
        [System.Console]::Write($ch*$num)
        continue
    }
}
PS src\static> .\Code\PowerShell\Challenge005.ps1

Challenge005.go

package main

import (
	"fmt"
	"strings"
	"regexp"
	"strconv"
)

func (c *Challenge) Challenge005()  {
	banner:="http://www.pythonchallenge.com/pc/def/banner.p"
	
	path:=".\\Data\\005"
	EnsureDir(path)

	filename:=path+"\\banner.p"
	Download(banner,filename)

	content:=ReadFile(filename)
	lines:=strings.Split(content,"\n")

	reln:=regexp.MustCompile("aa")
	renum:=regexp.MustCompile("^I([0-9]*)")
	rechsharp:=regexp.MustCompile("S'#'|g6")
	rechspace:=regexp.MustCompile("S' '|g2")

	ch:=" "

	for index := 0; index < len(lines); index++ {
		if reln.MatchString(lines[index]) {
			fmt.Printf("\n")
			continue
		}
		if rechsharp.MatchString(lines[index]) {
			ch="#"
			continue
		}
		if rechspace.MatchString(lines[index]) {
			ch=" "
			continue
		}
		matches:=renum.FindStringSubmatch(lines[index])
		if matches != nil {
			num,err:=strconv.Atoi(matches[1])
			if err == nil {
				for i:=0; i<num; i++ {
					fmt.Printf(ch)
				}
			}
			continue
		}
	}
}
PS src\static> .\Code\Go\Challenge.exe -l 005

最终结果: channel

[下一关地址][5]