2021-01-21

BUUCTF密码34到36题

34:RSA 1
看题目:
2021-01-21_第1张图片打开附件:
2021-01-21_第2张图片
打开pub.key,得到
2021-01-21_第3张图片
在线分解得到n,e
再用http://www.factordb.com
得到p,q
能力有限,抄的脚本T_T

import gmpy2
import rsa
 
e=65537
n=86934482296048119190666062003494800588905656017203025617216654058378322103517
p=285960468890451637935629440372639283459
q=304008741604601924494328155975272418463
 
phin = (p-1) * (q-1)
d=gmpy2.invert(e, phin)
 
key=rsa.PrivateKey(n,e,int(d),p,q)
 
with open("flag.enc","rb") as f:
    f=f.read()
    print(rsa.decrypt(f,key))

得到flag{decrypt_256}

35:异性相吸 1
看题目:
2021-01-21_第4张图片
打开附件:
有两个文件:用010editor打开
再用脚本进行二进制数异或
异或:二进制数a与b异或,即a和b两个数按位进行,如果对应位相同,即为0(这个时候相当于对应位算术相减),如果不相同,即为1(这个时候相当于对应位算术相减的绝对值)。由于二进制每个位只有两种状态,要么是0,要么是1,则按位异或操作可以表达为按位相减取绝对值,再按位累加。

举个例子:6(110)与3(011)异或为(101),按位相减为(1 0 -1)取绝对值是(101),在按位累加得5(101)。
2021-01-21_第5张图片
2021-01-21_第6张图片

a = '0110000101110011011000010110010001110011011000010111001101100100011000010111001101100100011000010111001101100100011000010111001101100100011000010111001101100100011000010111001101100100011000010111001101100100011000010111001101100100011000010111001101100100011100010111011101100101011100110111000101100110'b = '0000011100011111000000000000001100001000000001000001001001010101000000110001000001010100010110000100101101011100010110000100101001010110010100110100010001010010000000110100010000000010010110000100011000000110010101000100011100000101010101100100011101010111010001000001001001011101010010100001010000011011'
c = ''
for i in range(len(a)):
    if(a[i] == b[i]):
        c+='0'    
    else:        
        c+='1'
print(c)

运行得到
2021-01-21_第7张图片
在二进制转字符串得到flag

36:还原大师 1
看题目:
2021-01-21_第8张图片
这一题的解题思路是根据脚本来爆破,得到所有的结果,来跟残缺不全的MD5码进行对比得到flag

# -*- coding: utf-8 -*-
#!/usr/bin/env python
import hashlib

#print hashlib.md5(s).hexdigest().upper()
k = 'TASC?O3RJMV?WDJKX?ZM'                    #要还原的明文
for i in range(26):
	temp1 = k.replace('?',str(chr(65+i)),1)
	for j in range(26):
		temp2 = temp1.replace('?',chr(65+j),1)
		for n in range(26):
			temp3 = temp2.replace('?',chr(65+n),1)
			s = hashlib.md5(temp3.encode('utf8')).hexdigest().upper()#注意大小写
			if s[:4] == 'E903':    #检查元素
				print (s)       #输出密文

运行得到flag{E9032994DABAC08080091151380478A2}

你可能感兴趣的:(笔记)