代码拉取完成,页面将自动刷新
import socket
import os
from Cryptodome.Cipher import DES
import base64
import binascii
def pad(text):
"""
# 加密函数,如果text不是8的倍数【加密文本text必须为8的倍数!】,那就补足为8的倍数
:param text:
:return:
"""
while len(text) % 8 != 0:
text += ' '
return text
# 设置密钥&建立连接
key = "qwerpoiu".encode()
des = DES.new(key, DES.MODE_ECB)
sy = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sy.connect(('127.0.0.1', 8001))
str = input("请输入您要传输的文件名:")
sy.sendall("接收密钥".encode())
print("the message from ('127.0.0.1', 8001):",sy.recv(1024).decode())
sy.sendall(base64.b64encode(key))
print("the message from ('127.0.0.1', 8001):",sy.recv(1024).decode())
sy.sendall(str.encode())
os.chdir(r"C:\Users\98606\Desktop\1924")
file = open('{}'.format(str), 'r', encoding="utf8")
text = file.read()
padded_text = pad(text)
encrypted_text = des.encrypt(padded_text.encode('utf-8'))
sy.sendall(encrypted_text)
file.close()
data = sy.recv(1024)
print("the message from ('127.0.0.1', 8001):",data.decode())
sy.sendall("receive".encode())
sy.close()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。