python挑战赛怎么做trans_python challenge趣味挑战赛

第0关

>>>print 2 ** 38

274877906944L

替换网址为http://www.pythonchallenge.com/pc/def/274877906944.html

第1关

是个密码,字母往后移动两位,yz 变为 ab

#!/usr/bin/env python

# coding: utf-8

# author: toddlerya

# date: 2015-1-27

alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',

'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

goal = """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."""

alpha_dict = {'a': 0, 'c': 2, 'b': 1, 'e': 4, 'd': 3, 'g': 6, 'f': 5,

'i': 8, 'h': 7, 'k': 10, 'j': 9, 'm': 12, 'l': 11, 'o': 14,

'n': 13, 'q': 16, 'p': 15, 's': 18, 'r': 17, 'u': 20, 't': 19,

'w': 22, 'v': 21, 'y': 24, 'x': 23, 'z': 25}

result_dict = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h',

8: 'i', 9: 'j', 10: 'k', 11: 'l', 12: 'm', 13: 'n', 14: 'o',

15: 'p', 16: 'q', 17: 'r', 18: 's', 19: 't', 20: 'u',

21: 'v', 22: 'w', 23: 'x', 24: 'y', 25: 'z'}

#alpha_dict = dict([ (alpha[i], i) for i in range(0,26)] )

#result_dict = dict([ (i, alpha[i]) for i in range(0,26)] )

result_order = []

result = []

for a in goal:

if a in alpha:

i = alpha_dict[a]

if i 

j = i + 2

result_order.append(j)

elif 24 == i:

j = 0

result_order.append(j)

elif 25 == i:

j = 1

result_order.append(j)

#print result_order

for r in result_order:

x = result_dict[r]

result.append(x)

#print result

num = 0

for a in goal:

if a in alpha_dict:

print result[num],

num += 1

else:

print a,

过关密码:

i   h o p e   y o u   d i d n t   t r a n s l a t e   i t   b y   h a n d .

t h a t s   w h a t   c o m p u t e r s   a r e   f o r .   d o i n g   i t   i n   b y   h a n d

i s   i n e f f i c i e n t   a n d   t h a t ' s   w h y   t h i s   t e x t   i s   s o   l o n g .

u s i n g   s t r i n g . m a k e t r a n s ( )   i s   r e c o m m e n d e d .   n o w   a p p l y   o n   t h e   u r l .

按照提示改了下,好简洁。。。自己造轮子写的真丑。。。

#!/usr/bin/env python

# coding: utf-8

# author: toddlerya

# date: 2015-1-27

from string import maketrans

in_string = "abcdefghijklmnopqrstuvwxyz"

out_string = "cdefghijklmnopqrstuvwxyzab"

goal = """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."""

trans_string = maketrans(in_string, out_string)

print goal.translate(trans_string)

这次输出的好看多了:

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.

第2关

从提示可知道,查看源代码,找到一段注释

#!/usr/bin/env python

# coding: utf-8

# author: toddlerya

# date: 2015-1-27

# 把那一段注释里的内容 放到rare_char里面

rare_char = """

%%$@_$^__#)^)&!_+]!*@&^}@[@%]()%

省略n行

"""

tmp = []

for i in rare_char:

if i in tmp:

pass

else:

tmp.append(i)

print i, rare_char.count(i)

运行结果如下:

toddler@HP:~/Desktop$ python 3.py

1220

% 6104

$ 6046

@ 6157

_ 6112

^ 6030

# 6115

) 6186

& 6043

! 6079

+ 6066

] 6152

* 6034

} 6105

[ 6108

( 6154

{ 6046

e 1

q 1

u 1

a 1

l 1

i 1

t 1

y 1

可以看到最少字符是equality。这就是过关密码啦。改下url,下一关

第3关

目标要求的格式为xXXXxXXXx  正则搞定

那段待处理的文字放在src里

#!/usr/bin/env python

# coding: utf-8

# author: toddlerya

# date: 2015-1-28

import re

src = """

kAewtloYgcFQaJNhHVGxXDiQmz

……

"""

goal = re.findall("[a-z]{1}[A-Z]{3}[a-z]{1}[A-Z]{3}[a-z]{1}", src)

i = 0

for g in goal:

print goal[i][4],

i += 1

过关密码:

>>>

l i n k e d l i s t

替换equality为linkedlist

显示linkedlist.php

替换网址为linkedlist.php

进入第四关

第4关

点击图片跳转到新的页面,提示 :and the next nothing is 44827

……

改了两次发现这个应该用Python获取网络连接,然后改url访问下一次直到成功。。。

蠢哭了。。。

上Python

#!/usr/bin/env python

# coding: utf-8

# author: toddlerya

# date: 2015-1-28

import urllib2, re

nothing = "12345"

url_nothing = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing="

url = url_nothing + nothing

count = 1

while nothing:

try:

response = urllib2.urlopen(url, timeout=60)

html = response.read()

tmp = re.findall("[0-9]+", html)

nothing = ''.join(tmp)

url = url_nothing + nothing

print count, "\n", url

count += 1

except:

print html

这个网络也是醉了。。。等了好久。。。

最后结果

85

http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=16044

86

http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=

访问:http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=16044

提示信息:Yes. Divide by two and keep going.

改下代码nothing="8022",继续跑!!!丧心病狂啊

拿到密码:peak.html

第5关:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值