涉水The Python Challenge
在Stack Overflow 上看到学习Python 的一个方法是用Python 破解The Python Challenge。但我喜欢用Ruby,谁管得着呢^_^
0. 入门关很简单。
p 2**38
1. 破解一段话,观察图片很容易发现解码表把字母表循环右移两位。
riddle = "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."
riddle.scan(/./).each do |char|
if /[a-z]/ =~ char
print (?a + (char[0] - ?a + 2) % 26).chr
else
print char
end
end
译文: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.
再对url ("map")实施变换得"ocr"。
update: 发现String有个内置替换函数tr()。看,多简洁。
class String
def rot2
self.tr("a-xyz","c-zab")
end
end
p riddle.rot2
2. 查看网页源码,可以看到网页注释中有一堆乱码,上面有句话"find rare characters in the mess below:"(“找出稀少的字符”)。想到用hash 来统计各个字符的出现次数,并记录首次出现的顺序。
riddle = '...' # the mess here
count = Hash.new(0)
seq = []
riddle.scan(/./).each do |char|
seq << char if count[char] == 0
count[char] += 1
end
p count, seq
你会得到"equality"。第三关,我来了!
相关文档:
Python中执行系统命令常见方法有两种:
两者均需 import os
(1) os.system
# 仅仅在一个子终端运行系统命令,而不能获取命令执行后的返回信息
system(command) -> exit_status
Execute the command (a string) in a subshell.
# 如果再命令行下执行,结果直接打印出来
>>> os. ......
原文
http://www.hetland.org/python/instant-hacking.php
Instant Hacking[译
文]
译者: 肯定来过   ......
Help-》Software Upates-》Find and Install-》Search for new features to install-》New remote site-》随便起个name如pydev,url填 http://pydev.sf.net/updates/ -》然后照着提示下载安装即可。
Pydev的配置
在Eclipse IDE 下, 打开 Window->Preferences... 对话框,从右侧的树形列表中选择“ PyDev&r ......