You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
833 B

import base64 as b64
def encode_text(text):
"""Base64 编码"""
return b64.b64encode(text.encode('utf-8')).decode('utf-8')
def decode_text(text):
"""Base64 解码"""
try:
return b64.b64decode(text.encode('utf-8')).decode('utf-8')
except Exception:
return "解码失败,请检查输入是否合法"
def page():
"""工具页面"""
from flask import render_template, request
result = None
input_text = ""
action = request.args.get("action")
raw_text = request.args.get("text", "")
if raw_text:
input_text = raw_text
if action == "encode_text":
result = encode_text(raw_text)
elif action == "decode_text":
result = decode_text(raw_text)
return render_template("base64.html", result=result, input_text=input_text)