一位朋友在玩闯关游戏时遇到如下问题:
感觉考查的就是字符串操作,用string模块就可完成;代码如下:
# -*- coding: utf-8 -*- __author__ = 'Evilxr' import string _string =("Vm0wd2QyUXlVWGxWV30d4WFlURn164dVRlpzWkc5V" "1JteDBaVVYwV0ZKdGVGWlZiVFZyVmxVeFY3yTkljRmhoTVhCU" "VZtcEdZV015U2tWVWJHaG9UVlZ3VlZadGNFZFRNbEpJVm10V1" "VtSk3lRazlVVkVKTFUFAceB00BxWmtWMXBFVWxwV01ERTBWMn" "RvUjFWdF55NsWlhiR2hYWVd0d2RscFdXbUZrUjA1R1drWndWM" "DFFUlRGV1ZFb3dWakZhV0ZOcmFHaFNlbXhXVm0weGIxSkdXbG" "RYYlVaclVqRmFTRll5TVRSVk1rcElaSHBDVjAxdVVuWldha3B" "IWXpGT2RWVnNXbWxoTUhCWl4A4YxWlNSMlF52UmtkWGEyUllZ" "bGhT5V0ZSV1pGTk5SbFowWlVaT1ZXSkdjREZWVjNoelZqRmFO" "bEZZYUZaaGExcG9WakJhVDJOdFJrZFhiV3hUVFcxb2IxWnRjR" "U5pTVVWNFdrVmtXRmRIVWxsWmJHaFRZMVpTVjJGRlRsTmlSbk" "JaV2xWYVQxWlhTa2RqUm1oYVRVWktXRll3V21GU2JFNTBZVVp" "44rYUdFeGNHOVdha0poVXpGa1dGSnJaR2hTTW1oUFZGY3hiMW" "RzV1hoWGJFNVRUVlp3TUZadGRHdFdNa3B6VTIxR1ZWWjZWblp" "XUkVaVFZteGtjbHBIY0U1V2EzQlhWbFprTkZNeFRYaFhhMXBQ" "VmxacmJFMHdVU1V6UkElM0QlM0Q") mark = 0 while mark < len(_string) - 8: # 构造字符串 result = _string[mark: mark + 8] try: # 长度为8 assert len(result) == 8 except: print u'字符串长度不为8' break try: # 它的前两位是大写英文 assert result[0] in string.ascii_uppercase assert result[1] in string.ascii_uppercase # 它的3、4位是小写英文 assert result[2] in string.ascii_lowercase assert result[3] in string.ascii_lowercase # 它的第5位和第8位是同一个字符 assert result[4] == result[7] # 它的第6、7位是数字 assert result[5] in string.digits assert result[6] in string.digits print 'success', result break except: mark = mark +1
运行结果:
success FAceB00B
若非特别声明,文章均为Evilxr的个人笔记,转载请注明出处。