x11

摩斯电码解码,使用字典的方式,题目所给的分隔符是空格

data2=data2.decode().split()
def morse(message):
MorseList = {
".-": "A", "-...": "B", "-.-.": "C", "-..": "D", ".": "E", "..-.": "F", "--.": "G",
"....": "H", "..": "I", ".---": "J", "-.-": "K", ".-..": "L", "--": "M", "-.": "N",
"---": "O", ".--.": "P", "--.-": "Q", ".-.": "R", "...": "S", "-": "T",
"..-": "U", "...-": "V", ".--": "W", "-..-": "X", "-.--": "Y", "--..": "Z",

"-----": "0", ".----": "1", "..---": "2", "...--": "3", "....-": "4",
".....": "5", "-....": "6", "--...": "7", "---..": "8", "----.": "9",

".-.-.-": ".", "---...": ":", "--..--": ",", "-.-.-.": ";", "..--..": "?",
"-...-": "=", ".----.": "'", "-..-.": "/", "-.-.--": "!", "-....-": "-",
"..--.-": "_", ".-..-.": '"', "-.--.": "(", "-.--.-": ")", "...-..-": "$",
"....": "&", ".--.-.": "@", ".-.-.": "+",}
strings=''
for codes in message:
strings=strings+MorseList.get(codes)
return strings
data3=morse(data2)
print(data3)
s.send(data3.encode())

x12

一个字符串重复n次

string,num=data2.decode().split()
num=int(num)
data3=string*num
s.send(data3.encode())

x13

通过strip去除”[]”,再通过split分割成列表,使用sort进行排序

data2=data2.decode().strip('[]')
lists=data2.split()
lists.sort()
data3=lists[-1]
print(data3)
s.send(data3.encode())

x14

string1,string2=data2.decode().split()
num=0
for i in string1:
if i==string2:
num=num+1
data3=str(num)
print(data3)
s.send(data3.encode())

x15

通过观察是等差数列

lists=data2.decode().split()
lists=list(map(int,lists))
differ=lists[2]-lists[1]
data3=str(lists[-1]+differ)
s.send(data3.encode())

x16

使用pillow库来处理图片

import base64
from io import BytesIO
from PIL import Image

Bimage=base64.b64decode(data2)
image=Image.open(BytesIO(Bimage))
width,height=image.size
data3=f'{width}x{height}'
s.send(data3.encode())

x17

这题的意思是给了一个1个像素的经过base64编码的图片,需要返回这个像素rgba值的最后一位也就是a的值

import base64
from io import BytesIO
from PIL import Image

image=Image.open(BytesIO(Bimage))
rgba=image.getdata()[0]
data3=str(rgba[-1])
s.send(data3.encode())

x18

使用format,将字节格式化为8位二进制字符串然后拼接

data3 = ''.join(format(byte, '08b') for byte in data2)
s.send(data3.encode())

x19

使用zipfile库,base64解码之后对文件操作需要先转换成字节流的形式

import base64
import zipfile
import io
zip_data=base64.b64decode(data2)
zip_bytes=io.BytesIO(zip_data)
with zipfile.ZipFile(zip_bytes,'r') as zip_file:
txt_filename = zip_file.namelist()[0]
with zip_file.open(txt_filename) as txt_file:
content=txt_file.read().decode()
data3=content
s.send(data3.encode())

x20

先选取前50的rockyou字典保存为txt,使用hashlib创建hash对象,使用hexdigest获取hash值,一个个碰撞过来

import hashlib
data2=data2.decode()
words=[]
with open('rockyou.txt','r',encoding='utf-8') as file:
for line in file:
word=line.strip()
if word:
words.append(word)
for word in words:
if hashlib.md5(word.encode()).hexdigest()==data2:
break
data3=word
print(data3)
s.send(data3.encode())