Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import base64 # 匯入 base64 模組
- import time
- import os
- if os.name == "nt": # 如果系統是 Windows
- os.system ("title Base64Tool") # cmd 設定標題
- os.system ("cls") # Windows 底下,清除螢幕的指令為 cls
- else:
- os.system ("clear") # Mac & Linux 底下,清除螢幕的指令為 clear
- print ("\n\n\n") # Menu
- print ("1. 編碼字串至 Base64")
- print ("2. 解碼字串至 Base64")
- print ("3. 離開")
- option = input ("請輸入你想要的操作: ")
- if option == "1": # 如果使用者選擇 '1'
- b64encode = input ("請輸入欲編碼字串: ")
- encode_result = base64.b64encode(bytes(b64encode, 'utf-8')) # 先將使用者輸入之字串轉換為 bytes (以 utf-8 編碼)
- encode_result = str(encode_result) # 將編碼結果重新轉換為 str.
- print (b64encode + " 已編碼為 \nBase64: ", end="")
- print(str(encode_result.lstrip('b'))) # 將原結果前面的 'b' 去除
- elif option == "2": # 如果使用者選擇 '2'
- b64decode = input ("請輸入欲解碼字串 (base64): ")
- decode_result = base64.b64decode(bytes(b64decode, 'utf-8')) # 先將使用者輸入之字串轉換為 bytes (以 utf-8 編碼)
- decode_result = str(decode_result, 'utf-8') # 將解碼結果重新轉換為 str.
- print (b64decode + " 已解碼成 \n" + decode_result)
- else: # 如果使用者輸入 3 or other.
- print ("你沒有任何動作.")
- # creator: byStarTW
Advertisement
Add Comment
Please, Sign In to add comment