1 Star 0 Fork 0

Hanhao16 / hanhao17

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test13.py 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
849067634@qq.com 提交于 2020-05-16 11:19 . hanhao
import socket
#客户端
import os.path
from pyDes import des, CBC, PAD_PKCS5
import binascii
KEY = 'mHAxsLYz'
def des_encrypt(s):
secret_key = KEY
iv = secret_key
k = des(secret_key, CBC, iv, pad=None, padmode=PAD_PKCS5)
en = k.encrypt(s, padmode=PAD_PKCS5)
return binascii.b2a_hex(en)
def des_descrypt(s):
secret_key = KEY
iv = secret_key
k = des(secret_key, CBC, iv, pad=None, padmode=PAD_PKCS5)
de = k.decrypt(binascii.a2b_hex(s), padmode=PAD_PKCS5)
return de
os.mkdir(r"F:\python编程\1621")
file = open(r"F:\python编程\1621\162116.txt","a")
file.write("20162116")
choice = input("您是否要写文件(yes or no):")
while choice == "yes":
content = input("请输入您要写的内容:")
file.write(content)
choice = input("您是否要继续添加信息(yes or no):")
file.close()
oth_choice = input("您是否要读文件并传输(yes or no):")
if oth_choice == "yes":
file = open(r"F:\python编程\1621\162116.txt", "r")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', 8001))
str = file.read()
pass_hex = des_encrypt(str)
s.sendall(pass_hex)
data = s.recv(1024)
print(data.decode())
s.close()
file.close()
else:
print("谢谢使用!")
1
https://gitee.com/hanhao16/hanhao17.git
git@gitee.com:hanhao16/hanhao17.git
hanhao16
hanhao17
hanhao17
master

搜索帮助