#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project :python-learn
@File :base64加解密.py
@Author :星之尘
@Date :2023/6/12 20:40
@脚本说明:
"""
import base64
def base64_encode(data):
encoded_bytes = base64.b64encode(data.encode())
encoded_string = encoded_bytes.decode()
return encoded_string
def base64_decode(data):
decoded_bytes = base64.b64decode(data)
decoded_string = decoded_bytes.decode()
return decoded_string
def base64main():
choice = input("请选择操作(1:加密,2:解密):")
if choice == "1":
plaintext = input("请输入要加密的字符串:")
encrypted_data = base64_encode(plaintext)
print("加密后:", encrypted_data)
elif choice == "2":
ciphertext = input("请输入要解密的字符串:")
decrypted_data = base64_decode(ciphertext)
print("解密后:", decrypted_data)
else:
print("无效的选择。")
if __name__ == "__main__":
base64main()
base64加解密python脚本
于 2023-07-06 16:22:23 首次发布