python3 base64


import base64

s='hello world'
bytes_by_s=s.encode() #將字符串編碼-->字節碼,
b64_encode_bytes=base64.b64encode(bytes_by_s) #base64編碼
print(b64_encode_bytes)


b64_decode_bytes=base64.b64decode(b64_encode_bytes) #base64解碼
print(b64_decode_bytes)
s_by_bytes=b64_decode_bytes.decode() #字節碼解碼-->字符串
print(s_by_bytes)

輸出:

b'aGVsbG8gd29ybGQ='
b'hello world'
hello world

 


 

base64更改編碼表:

std_base= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
mg_base= "tuvwxTUlmnopqrs7YZabcdefghij8yz0123456VWXkABCDEFGHIJKLMNOPQRS9+/="

en_trantab = str.maketrans(std_base, mg_base) # 制作翻譯表
de_trantab=str.maketrans(mg_base,std_base)
import base64

s='hello world'
stden=base64.b64encode(s.encode()).decode()
print('標准base64編碼:'+stden)
enstr=stden.translate(en_trantab)
print('修改base64編碼:'+enstr)

t=enstr.translate(de_trantab).encode()
mgs=base64.b64decode(t).decode()
print(mgs)


輸出:

標准base64編碼:aGVsbG8gd29ybGQ=
修改base64編碼:iUdCjUS1yM9IjUY=
hello world





 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM