Chinaunix首页 | 论坛 | 博客
  • 博客访问: 576502
  • 博文数量: 226
  • 博客积分: 10080
  • 博客等级: 上将
  • 技术积分: 1725
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-26 11:15
文章分类

全部博文(226)

文章存档

2011年(5)

2010年(64)

2009年(99)

2008年(37)

2007年(21)

我的朋友

分类: LINUX

2010-04-21 20:38:47

   在这个网站:有python的挑战题目,嘿嘿,从第二题开始做起,
 
给一段乱码:
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
 
有个图片:E-》G
 
我写了转换:
for i in str:
    if i>='a' and i<='x':
        tmp = tmp + chr(ord(i)+2)
    elif i>'x' and i<='z':
        tmp = tmp + chr(ord(i)+2-26)
    else:
        tmp = tmp+i
 
得到结果:
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
 
O(∩_∩)O~,难怪说要转换两次,转换URL吧:
 
transtab= string.maketrans('abcdefghijklmnopqrstuvwxyz','cdefghijklmnopqrstuvwxyzab')
str.translate(transtab,'')
"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"
tmp="map"
tmp.translate(transtab,'')
'ocr'
 
得到第三题的链接:
下次再做吧。。
 
阅读(1273) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~