#加密
import binascii
def hex_encrypt(text):
# 将字符串转换为字节
text_bytes = text.encode('utf-8')
# 将字节转换为十六进制字符串
hex_str = binascii.b2a_hex(text_bytes)
return hex_str.decode('utf-8')
# 测试代码
text = input("请输入要加密的文字:")
encrypted_text = hex_encrypt(text)
print("加密后的结果为:", encrypted_text)
#解密
import binascii
hex_string = input("请输入16进制字符串:")
byte_string = binascii.a2b_hex(hex_string)
print("解密后的字节字符串为:", byte_string)

Comments NOTHING