加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python3 base64

发布时间:2020-12-20 10:50:30 所属栏目:Python 来源:网络整理
导读: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_decod
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更改编码表:

mg_base=  "tuvwxTUlmnopqrs7YZabcdefghij8yz0123456VWXkABCDEFGHIJKLMNOPQRS9+/="

std_base= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="

trantab = str.maketrans(std_base,mg_base) # 制作翻译表

import base64

s=‘hello world‘
bytes_by_s=s.encode()
b64_encode_bytes=base64.b64encode(bytes_by_s)
print(b64_encode_bytes)

mgs=b64_encode_bytes.decode().translate(trantab)
print(mgs)


输出:

b‘aGVsbG8gd29ybGQ=‘iUdCjUS1yM9IjUY=

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读