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更改编码表:

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=



 

转载于:https://www.cnblogs.com/DirWang/p/11430768.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值