实验吧编程类题目

小猴子爱吃桃子

猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个 第二天早上又将剩下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下的一半零一个。到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。
格式:CTF{}

1
2
3
4
num = 1
for i in range(9):
num = (num+1)*2
print(num)

找素数

设一个等差数列,首元素为367,公差为186, 现在要求找出属于该等差数列中的第151个素数并输出。
格式:CTF{xxx}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
sushu = 0
num = 367
while True:
if sushu < 151:
yushu = 0
for i in range(2,num-1):
if num%i == 0:
yushu = 1
break
if yushu == 0:
sushu = sushu + 1
if sushu == 151:
print(num)
break
num = num + 186

分数拆分

存在这样的一个等式,1/400=1/x+1/2y,(x>y)。
你的任务就是求出共有多少对这样的正整数x和y,使得该等式成立。
(提示:你只需要求出有多少对,而不必输出这些X,Y对具体是多少)
hint:CTF{xxx}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 1、根据题目等式,可以知道x=400*y)/(y-200),因为x和y都是正整数,且考虑分母不为0,所以这里可以确定y的最小值为201;
# 2、因为1/400=1/x+1/2
# y,(x > y),考虑极限情况,可以使得x等于y,因分母变小,即分数整体值增大,即等式变成:1 / 400 < 1 / y + 1 / 2
# y,可以得出y < 600,即得到y的最大值可以为599;
# 3、根据y的变化范围进行编程实现,具体代码如下(这里输出了x:y的值):

count=0
num_list=[]
for y in range(201,600):
if (400*y)%(y-200)==0:
count=count+1
str_add=str((400*y)/(y-200))+':'+str(y)
num_list.append(str_add)

print(num_list)
print('CTF{'+str(count)+'}')

Hashkill

6ac66ed89ef9654cf25eb88c21f4ecd0是flag的MD5码,(格式为ctf{XXX_XXXXXXXXXXX_XXXXX})
由一个0-1000的数字,下划线,纽约的一个区,下划线,一个10000-15000的数字构成。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import hashlib

qu = ["thebronx","brooklyn","manhattan","queens","statenisland"]
MD5 = "6ac66ed89ef9654cf25eb88c21f4ecd0"

def hash():
for a in range(0,1001):
for b in qu:
for c in range(10000,15001):
flag = "ctf{" + str(a) + "_" + str(b) + "_" + str(c) + "}"
flaghash = hashlib.md5(flag.encode('utf-8')).hexdigest()
# print(flaghash)
if flaghash == MD5:
return flag

if __name__ == "__main__":
flagmd5 = hash()
print(flagmd5)

考考你的程序功底

给定一个20行20列的数表,求其中在一条线上(行、列、两个对角线)连续4个数的乘积的最大值。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
a = [8,2,22,97,38,15,0,40,0,75,4,5,7,78,52,12,50,77,91,8]
b = [49,49,99,40,17,81,18,57,60,87,17,40,98,43,69,48,4,56,62,0]
c = [81,49,31,73,55,79,14,29,93,71,40,67,53,88,30,3,49,13,36,65]
d = [52,70,95,23,4,60,11,42,69,24,68,56,1,32,56,71,37,2,36,91]
e = [22,31,16,71,51,67,63,89,41,92,36,54,22,40,40,28,66,33,13,80]
f = [24,47,32,60,99,3,45,2,44,75,33,53,78,36,84,20,35,17,12,50]
g = [32,98,81,28,64,23,67,10,26,38,40,67,59,54,70,66,18,38,64,70]
h = [67,26,20,68,2,62,12,20,95,63,94,39,63,8,40,91,66,49,94,21]
i = [24,55,58,5,66,73,99,26,97,17,78,78,96,83,14,88,34,89,63,72]
j = [21,36,23,9,75,0,76,44,20,45,35,14,0,61,33,97,34,31,33,95]
k = [78,17,53,28,22,75,31,67,15,94,3,80,4,62,16,14,9,53,56,92]
l = [16,39,5,42,96,35,31,47,55,58,88,24,0,17,54,24,36,29,85,57]
m = [86,56,0,48,35,71,89,7,5,44,44,37,44,60,21,58,51,54,17,58]
n = [19,80,81,68,5,94,47,69,28,73,92,13,86,52,17,77,4,89,55,40]
o = [4,52,8,83,97,35,99,16,7,97,57,32,16,26,26,79,33,27,98,66]
p = [88,36,68,87,57,62,20,72,3,46,33,67,46,55,12,32,63,93,53,69]
q = [4,42,16,73,38,25,39,11,24,94,72,18,8,46,29,32,40,62,76,36]
r = [20,69,36,41,72,30,23,88,34,62,99,69,82,67,59,85,74,4,36,16]
s = [20,73,35,29,78,31,90,1,74,31,49,71,48,86,81,16,23,57,5,54]
t = [1,70,54,71,83,51,54,69,16,92,33,48,61,43,52,1,89,19,67,48]
lists = []
lie = [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t]
# 行
for j in lie:
for i in range(17):
product = j[i] * j[i+1] * j[i+2] * j[i+3]
print(product)
lists.append(product)

# 列
for j in range(20):
for i in range(17):
product = (lie[i])[j] * (lie[i+1])[j] * (lie[i+2])[j] * (lie[i+3])[j]
print(product)
lists.append(product)

# 对角线1
for j in range(17):
for i in range(17):
product = (lie[i])[j] * (lie[i+1])[j+1] * (lie[i+2])[j+2] * (lie[i+3])[j+3]
print(product)
lists.append(product)

# 对角线2
for j in range(17):
for i in range(17):
product = (lie[16-i])[j+3] * (lie[16-i+1])[j+2] * (lie[16-i+2])[j+1] * (lie[16-i+3])[j]
print(product)
lists.append(product)

print(lists)
print(max(lists))

KEY:IL0V3Pr0Gr4m@#!!

括号表达式

一个括号表达式可以按照如下的规则表示,就是每个右括号之前的左括号数。
比如(((()()()))),每个右括号之前的左括号数序列为P=4 5 6 6 6 6,而每个右括号所在的括号内包含的括号数为W=1 1 1 4 5 6。
现在给定一个括号表达式为 4 6 6 6 6 8 9 9 9,输出每个右括号所在的括号内包含的括号数。
key格式:CTF{xxx}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 这道题要写,数都数得来,画画图或者模拟整个过程一定会出来结果,我们不妨看看能否找出规律。
# 举个例子,P=4 5 6 6 6 6,而每个右括号所在的括号内包含的括号数为W=1 1 1 4 5 6。
# P中的每一个数可以代表的是一个右括号,则数字4,不用说,必然与前面一左括号匹配,
# 即为,数字4与5之间两个右括号有(5-4)个左括号,而数字4与5之间没有其他数字也即没有其他右括号
# ,则这个左括号必然是与数字5所代表的右括号匹配,则也为1,同理数字5与6也是这样,到了第二个数字6,
# 其往前找到第一个数字6,中间没有左括号,则继续往前找到5,数字5与数字6中间有(6-5)个左括号,
# 而两个数之间还有一个右括号,则不行,得继续往前,找到4,同理不行,前面没有数了,那么就看这个数字6(第二个的)在p中是第几个就好了,
# 应该说是与找到合理的数字下表之差,往后依旧。则对于4 6 6 6 6 8 9 9 9 即为 1 1 2 4 5 1 1 3 9 转化为代码即为
left = [0,4,6,6,6,6,8,9,9,9]
lists = []
for i in range(1,len(left)):
j = i - 1
while(left[i]-left[j]<i-j):
j = j-1
print(i-j)
lists.append(i-j)
print("%d%d%d%d%d%d%d%d%d"%(lists[0],lists[1],lists[2],lists[3],lists[4],lists[5],lists[6],lists[7],lists[8]))

斐波那契数列

数列A满足An = An-1 + An-2 + An-3, n >= 3
编写程序,输入A0, A1 和 A2的值1 1 1时, 计算A99的高八位。
key格式:CTF{}

1
2
3
4
5
6
7
8
9
10
11
12
def A(num):
a,b,c = 1,1,1
if num < 3:
print(1)
for i in range(num-2):
a,b,c = b,c,c+a+b
return c

if __name__ == "__main__":
a = A(99)
print(a)
print("CTF{"+ str(a)[:8] + "}")

大数据问题

小明刚刚学习计算机编程,老师给他出了这样一道题目,
但是他怎样思考,都做不出来,于是,只好请教高手的你了。
求sum = 1!+2!+3!+……+6788!+6789!的末5位。
提交格式:SimCTF{}

1
2
3
4
5
6
7
8
9
import math

a = 25
sum = 0
for i in range(1,a):
j = math.factorial(i)
sum += j

print(str(sum)[-5:])

三羊献瑞

观察下面的加法算式:
   祥 瑞 生 辉
 + 三 羊 献 瑞
-——————
 三 羊 生 瑞 气

其中,相同的汉字代表相同的数字,不同的汉字代表不同的数字。
请计算“三羊献瑞”四个字分别代表的数字
答案格式:CTF{xxxx},xxxx为“三羊献瑞”四个字分别代表的数字

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#设:祥=a,瑞=b,生=c,辉=d,三=e,羊=f,献=g,气=h
# 可以推出a=9,e=1,f=0
a = 9
e = 1
f = 0
def yang():
for b in range (0,10):
for c in range (0,10):
for d in range (0,10):
for g in range (0,10):
for h in range (0,10):
print(a, b, c, d, e, f, g, h)
if(a*1000+b*100+c*10+d+e*1000+f*100+g*10+b)==(e*10000+f*1000+c*100+b*10+h):
if(a!=b)and(a!=c)and(a!=d)and(a!=e)and(a!=f)and(a!=g)and(a!=h):
if(b!=c)and(b!=d)and(b!=e)and(b!=f)and(b!=g)and(b!=h):
if(c!=d)and(c!=e)and(c!=f)and(c!=g)and(c!=h):
if(d!=e)and(d!=f)and(d!=g)and(d!=h):
if(e!=f)and(e!=g)and(e!=h):
if(f!=g)and(f!=h):
if(g!=h):
print("三=%s,羊=%s,献=%s,瑞=%s"%(e,f,g,b))
print(a,b,c,d,e,f,g,h)
return str(e)+str(f)+str(g)+str(b)

if __name__ == '__main__':
flag = yang()
print("CTF{" + flag + "}")

速度爆破

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from urllib import request,parse
from hashlib import md5,sha1


list = {}
for i in range(100001):
Sha1 = sha1((md5(str(i).encode('utf-8')).hexdigest()).encode('utf-8')).hexdigest()
list[Sha1] = i

def main():
url='http://ctf5.shiyanbar.com/ppc/sd.php'
req = request.Request(url)
req.add_header("Cookie","PHPSESSID=ga0un6plm7tea9li11bgnommh1")
# print(req)
response = request.urlopen(req)
html = response.read().decode('utf-8')
a = html.find('color:red')
str = html[a+11:a+40+11]
# print(str)
num = list[str]
params = {'inputNumber':num}
# print(params)
params = parse.urlencode(params).encode('utf-8')
response = request.urlopen(req, params)
print(response.read().decode('utf-8'))


main()

for resquests:↓

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import requests,re
from hashlib import md5,sha1

# 生成字典
list = {}
for i in range(100001):
Sha1 = sha1((md5(str(i).encode('utf-8')).hexdigest()).encode('utf-8')).hexdigest()
list[Sha1] = i
# print(list)

def main():
url = 'http://ctf5.shiyanbar.com/ppc/sd.php'
s = requests.session()
req = s.get(url)
req.encoding = 'utf-8'
# print(req.text)
Str = re.findall(r'>(.*)</div>',req.text)
response = s.post(url,data={'inputNumber':list[Str[0]]})
response.encoding = 'utf-8'
print(response.text)

main()

ASCII艺术

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from urllib import request,parse
import re

def main():
url='http://ctf5.shiyanbar.com/ppc/acsii.php'
req = request.Request(url)
req.add_header("Cookie","PHPSESSID=ga0un6plm7tea9li11bgnommh1")
# print(req)
response = request.urlopen(req)
html = response.read().decode('utf-8')
# print(html)
a = r':red">(.*?)</div>'
content = re.findall(a,html)[0]
# print(content)
num = str(content)
# print(num)
num = num.replace('&nbsp;xxx&nbsp;<br />x&nbsp;&nbsp;&nbsp;x<br />x&nbsp;&nbsp;&nbsp;x<br />x&nbsp;&nbsp;&nbsp;x<br />&nbsp;xxx&nbsp;<br />','0')
num = num.replace('&nbsp;xx<br />&nbsp;&nbsp;x&nbsp;x&nbsp;&nbsp;<br />&nbsp;&nbsp;x&nbsp;&nbsp;<br />&nbsp;&nbsp;x&nbsp;&nbsp;<br />xxxxx<br />','1')
num = num.replace('&nbsp;xx<br>&nbsp;&nbsp;x&nbsp;x&nbsp;&nbsp;<br>&nbsp;&nbsp;x&nbsp;&nbsp;<br>&nbsp;&nbsp;x&nbsp;&nbsp;<br>xxxxx<br><br/>','1')
num = num.replace('&nbsp;xxx&nbsp;<br />x&nbsp;&nbsp;&nbsp;x&nbsp;<br />&nbsp;&nbsp;xx&nbsp;<br />&nbsp;x&nbsp;&nbsp;&nbsp;<br />xxxxx<br />','2')
num = num.replace('&nbsp;xxx&nbsp;<br />x&nbsp;&nbsp;&nbsp;x<br />&nbsp;&nbsp;xx&nbsp;<br />x&nbsp;&nbsp;&nbsp;x<br />&nbsp;xxx&nbsp;<br />','8')
num = num.replace('xxxxx<br />x&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;xxxx<br />&nbsp;&nbsp;&nbsp;&nbsp;x<br />xxxxx<br />', '5')
num = num.replace('&nbsp;x&nbsp;&nbsp;&nbsp;x<br />x&nbsp;&nbsp;&nbsp;&nbsp;x<br />&nbsp;xxxxx<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x<br />&nbsp;&nbsp;&nbsp;&nbsp;x<br />','4')
num = num.replace('xxxxx<br />x&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;xxxx<br />&nbsp;&nbsp;&nbsp;&nbsp;x<br />xxxxx<br />', '5')
num = num.replace('<br/>', '')

# print(num)
params = {'inputNumber':num}
# print(params)
params = parse.urlencode(params).encode('utf-8')
response = request.urlopen(req, params)
print(response.read().decode('utf-8'))

# 简化输出
# response = response.read().decode('utf-8')
# # print(response)
# key = r"<div id='msg'>(.*?)</div>"
# flag = re.findall(key,response)[0]
# print(flag)


main()

for requests:↓

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import re,requests

def main():
url = 'http://ctf5.shiyanbar.com/ppc/acsii.php'
s = requests.session()
req = s.get(url)
req.encoding='utf-8'
# print(req.text)
a = r':red">(.*?)</div>'
content = re.findall(a,req.text)[0]
# print(content)
num = str(content)
# print(num)
num = num.replace('&nbsp;xxx&nbsp;<br />x&nbsp;&nbsp;&nbsp;x<br />x&nbsp;&nbsp;&nbsp;x<br />x&nbsp;&nbsp;&nbsp;x<br />&nbsp;xxx&nbsp;<br />','0')
num = num.replace('&nbsp;xx<br />&nbsp;&nbsp;x&nbsp;x&nbsp;&nbsp;<br />&nbsp;&nbsp;x&nbsp;&nbsp;<br />&nbsp;&nbsp;x&nbsp;&nbsp;<br />xxxxx<br />','1')
num = num.replace('&nbsp;xx<br>&nbsp;&nbsp;x&nbsp;x&nbsp;&nbsp;<br>&nbsp;&nbsp;x&nbsp;&nbsp;<br>&nbsp;&nbsp;x&nbsp;&nbsp;<br>xxxxx<br><br/>','1')
num = num.replace('&nbsp;xxx&nbsp;<br />x&nbsp;&nbsp;&nbsp;x&nbsp;<br />&nbsp;&nbsp;xx&nbsp;<br />&nbsp;x&nbsp;&nbsp;&nbsp;<br />xxxxx<br />','2')
num = num.replace('&nbsp;xxx&nbsp;<br />x&nbsp;&nbsp;&nbsp;x<br />&nbsp;&nbsp;xx&nbsp;<br />x&nbsp;&nbsp;&nbsp;x<br />&nbsp;xxx&nbsp;<br />','8')
num = num.replace('xxxxx<br />x&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;xxxx<br />&nbsp;&nbsp;&nbsp;&nbsp;x<br />xxxxx<br />', '5')
num = num.replace('&nbsp;x&nbsp;&nbsp;&nbsp;x<br />x&nbsp;&nbsp;&nbsp;&nbsp;x<br />&nbsp;xxxxx<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x<br />&nbsp;&nbsp;&nbsp;&nbsp;x<br />','4')
num = num.replace('xxxxx<br />x&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;xxxx<br />&nbsp;&nbsp;&nbsp;&nbsp;x<br />xxxxx<br />', '5')
num = num.replace('<br/>', '')
# print(num)
response = s.post(url,data={'inputNumber':num})
response.encoding = 'utf-8'
# print(response.text)
flag = re.findall(r'id=\'msg\'>(.*)</div>',response.text)
print(flag[0])

main()

百米

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import re,requests

def main():
url = 'http://ctf5.shiyanbar.com/jia/index.php'
s = requests.session()
req = s.get(url)
req.encoding='gb2312'
# print(req.text)
math = re.findall(r'my_expr\'>(.*)</div>',req.text)
# print(math[0])
math = math[0].replace('x','*')
# print(math)
math = eval(math)
# print(math)
response = s.post(url,data={'pass_key':math})
response.encoding='gb2312'
print(response.text)

main()

求解!

密文xztiofwhf是用仿射函数y=5x+11加密得到的

1
2
3
4
5
6
7
8
9
10
11
12
13
list = 'abcdefghijklmnopqrstuvwxyz'
newlist = ''

for i in range(len(list)):
newlist += list[(5 * i + 11 ) % 26]


y = 'xztiofwhf'
x = ''
for j in y:
x += list[newlist.find(j)] #查找新列表字符对应的位置,在旧列表同样的位置即为flag

print(x)

海量约瑟夫问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
n=57109519409189850198608692898492839208109598203852985209815058928520938958906207207017014242749827958752975981705872782758927827398578971498749287481591758917982491
kill1 = False
start = 1
sep = 1
while n != 2:
killn = n / 2
if n%2 == 1 and kill1:
killn = killn + 1 #杀第一人且n为奇则杀n/2+1人
if kill1:
start = start + sep
sep = sep * 2
if n%2 == 1: #n为奇则改变杀开头的第一人还是第二人
kill1 = not kill1
n = n - killn

print(start+sep)%129119417519

算术题

一道小学算术题,但是好多老师不会,不知道为什么

从外圈最小的开始顺时针旋转:6531031914842725

能看到吗

writeup:西普CTF-能看到吗

双基回文数

计算大于正整数1600000的最小双基回文数
别人的python2脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#coding:utf-8
sum=1600000
def handle(value,hex_number): #将数转换成不同进制的字符串
sss=''
while(value!=0):
sss+=str(value%hex_number)
value=((value-value%hex_number)/hex_number)
return sss[::-1]

def ok(aaa): #判断字符串是否为回文数
length=len(aaa)
for i in range(0,length/2):
if aaa[i]!=aaa[length-1-i]:
return False
return True

while(1):
times=0
for i in range(2,11):
if(ok(handle(sum,i))): #统计次数
times+=1
if times>1:
print sum
break
sum+=1

约瑟夫环

总共有2 * k个人报数,前面k个是好人,后面k个是坏人,从第一个好人开始报数,报道m的人要死去。然后从死人的下一个活人继续从头开始报数,报道m的人死去,以此类推。当k = 12时,问m为何值时,坏人全部死去之前不会有好人死去。

1
2
3
4
5
6
7
8
9
10
11
约瑟夫循环,我这里利用python的列表进行del删除,设第m个数死,则去掉的位置为
(当前位置m-1)%当前长度
约瑟夫循环没问题之后就是暴力了,分享我的代码~
for i in range(1,2000000):
sss=[1]*12+[0]*12
k=0
for j in range(12): #看12杀人之后的结果
k=(k+i-1)%(24-j)
del(sss[k])
if [1]*12==sss:
print(i)

迷宫大逃亡

参考:BFS算法(迷宫大逃亡writeup)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# coding=utf-8
import threading
import time
import base64
def openfile():
result = ""
f = open("ini.txt", "r")
i=int(f.readline().strip())
while (i != 0):
line=None
while not line:
line = f.readline().strip()
scale = int(line)
start = []
for x in f.readline().strip().split():
start.append(int(x)-1)
end = []
for x in f.readline().strip().split():
end.append(int(x)-1)
migong = []
for _ in range(scale):
migong.append(f.readline().strip())
r=pyqueue(len(migong[0]), start, end, migong)
result+=str(r.run())
i = i - 1
#print result
print result
flag=""
for i in range(0,len(result),8):
c = result[i:i+8]
flag+=chr(int(c,2))
print base64.b64decode(flag)
class pyqueue:
def __init__(self, _len, _start, _end, _migong):
self.len = _len #地图尺寸
self.start = _start #起点
self.end = _end #终点点 格式 [x,y]
self.migong = _migong #地图
self.queue = [self.start] #初始的地方
self.steptrace = [] #走过的地方
self.sucess = 0 #判断找到了终点
def Iqueue(self, location):
self.queue.append(location)
self.steptrace.append(location)

def Oqueue(self):
temp = self.queue[0]
del (self.queue[0])
return temp

def Void(self, location):
try:
if location in self.steptrace or self.migong[location[0]][location[1]] == "X":
return
else:
if location == self.end:
self.sucess=1
return
self.steptrace.append(location)
self.Iqueue(location)
return
except:
print "error"
print location

def empty(self):
try:
self.queue[0]
return True
except IndexError:
return False

def addx(self, x):
x += 1
if x >= self.len: return x - 1
return x

def subx(self, x):
x -= 1
if x < 0: return x + 1
return x

def run(self):
return str(self.zoumigong())

def zoumigong(self):
while self.empty():
location = self.Oqueue()
#print location
self.Void([self.addx(location[0]),location[1]])
self.Void([self.subx(location[0]), location[1]])
self.Void([location[0],self.addx(location[1])])
self.Void([location[0], self.subx(location[1])])
# 上下左右各试探一下
if self.sucess==1:
return 1
return 0

# localtion=[x,y]
# migong[location[0],local[1]]

if __name__ == '__main__':
openfile()

flag很坑,访问输出的url(去掉flagsiurl),题目的链接就是flag,格式CTF{}

CTF{http://ctf5.shiyanbar.com/crypto/Crypto1}

小球下落

1
2
3
4
5
6
7
8
9
10
11
12
13
14
a = [0 for x in range(65536)]
for i in range(0,12345):
tmp=1
for x in range(0,15):

if(a[tmp]==0):
a[tmp]=~a[tmp]
tmp=tmp*2
else:
a[tmp]=~a[tmp]
tmp=tmp*2+1

if(i==12344):
print(tmp)

普里姆路径

参考:西普CTF-普里姆路径

大数模运算

1
2
3
4
5
6
7
8
9
10
11
for i in range(2,12345):
if 12345%i==0:
print(i)
key=12345
sum=0
key1=key2=key3=0
for i in range(0,12346):
key1+=3**i%9901
key2+=5**i%9901
key3+=823**i%9901
print((key1*key2*key3)%9901)

Noise

参考:西普CTF-Noise
他的代码比较早了,下面给出我改过后的python3脚本,需要安装Pillow

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from PIL import Image
def foo():
im=Image.open("noise.png")
pix=im.load()
width,height=im.size

bgcolor=(255,255,255)
im2= Image.new('RGB',(width,height),bgcolor)
pix2=im2.load()

count=0
for x in range(0,width):
for y in range(0,height):
g,b=pix[x,y][1:]
pix2[g,b]=(0,0,0)
count+=1
if count==12000:
break
else:
continue
break
im2.show()
pass

if __name__ == '__main__':
foo()
print('ok')

聪明的打字员

传送门:BFS和DFS算法分析对比及优化

二叉树遍历

#
参考:西普CTF-两个最大子串和

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
a=[-132,133,134,-11,12,-139,-140,62,63,-64,65,66,67,
1,2,3,4,5,-6,7,-48,-49,50,138,16,17,20,
101,102,-103,104,-105,106,146,147,148,-107,108,109,110,96,
21,-22,23,-24,-25,25,-27,-28,-29,30,
41,-42,8,9,10,-46,-47,
51,52,-53,54,-55,-56,57,-58,59,60,
73,-74,75,-71,-72,18,-97,-98,19,-129,130,
-137,136,-13,14,144,-145,15,128,
77,-78,-31,32,35,-76,149,-150,99,100,119,
91,-92,-93,94,95,116,117,114,118,120,
81,82,83,-84,85,-122,-123,
112,111,-43,44,45,-113,-115,36,-37,-38,39,40,25,126,127,
131,-135,61,-69,70,
141,-142,143,-86,68,-87,-90,
121,-88,89,-124,-179,-80,-33,34]
value1=[-99999]*150
value2=[-99999]*150
max=0
sum=0
for i in range(0,150):
sum+=a[i]
if max<sum:
max=sum
value1[i]=max
if sum<0:
sum=0
max=0
sum=0
for i in range(149,-1,-1):
sum+=a[i]
if max<sum:
max=sum
value2[i]=max
if sum<0:
sum=0
max=0
for i in range(0,149):
if(value1[i]+value2[i+1]>max):
max=value1[i]+value2[i+1]
print(max)