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



python3 base64的更多相关文章

  1. python3 base64模块代码分析

    #! /usr/bin/env python3 """Base16, Base32, Base64 (RFC 3548), Base85 and Ascii85 data ...

  2. python3 base64解码出现TypeError:Incorrect padding

    今天在解决爬虫对加密参数的分析时,需要使用到base64解码.但是过程中出现了TypeError:Incorrect padding的错误提示.以下是解决方法,以便查阅. 其实正常使用base64是不 ...

  3. python3解析网页经过base64编码后的图片

    有时候我们打开网页看到的图片不是普通的url,例如:www.baidu.com/static/2.jpg,而是经过base64方式加密过的路径:例如:data:img/jpg;base64,/9j/4 ...

  4. python2与python3下的base64模块

    Python2的编解码 python2中程序数据类型默认为ASCII,所以需要先将数据解码(decode)成为Unicode类型,然后再编码(encode)成为想要转换的数据类型(gbk,utf-8, ...

  5. scrapy怎么设置带有密码的代理ip base64.encodestring不能用 python3.5,base64库里面的encodestring()被换成了什么?

    自己写爬虫时买的代理ip有密码,在网上查了都是下面这种: 1.在Scrapy工程下新建"middlewares.py": import base64 # Start your mi ...

  6. python3的base64编解码

    使用python3的base64编解码实现字符串的简易加密解密 引言: 在一些项目中,接口的报文是通过base64加密传输的,所以在进行接口自动化时,需要对所传的参数进行base64编码,对拿到的响应 ...

  7. Python3 内建模块 datetime/collections/base64/struct

    datetime 我们先看如何获取当前日期和时间: >>> from datetime import datetime >>> now = datetime.now ...

  8. python3 解析 base64 数据

    在阅读 glTF-Tutorial 教程时遇到了解析 base64 数据的问题. 原始 base64 数据为AAABAAIAAAAAAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAA ...

  9. Python3模块-random、hashlib和base64

    random模块 random.random()用于生成一个浮点数x,范围为0 =< x < 1 import random >>>print(random.random ...

随机推荐

  1. 白日梦的ES笔记三:万字长文 Elasticsearch基础概念统一扫盲

    目录 一.导读 二.彩蛋福利:账号借用 三.ES的Index.Shard及扩容机制 四.ES支持的核心数据类型 4.1.数字类型 4.2.日期类型 4.3.boolean类型 4.4.二进制类型 4. ...

  2. vue 的 computed 属性在什么时间执行

    vue 的 computed 属性在什么时间执行

  3. Vue 3 In Action

    Vue 3 In Action $ yarn add vue https://v3.vuejs.org demos refs https://v3.vuejs.org/guide/migration/ ...

  4. background & background-image & border-image

    background & background-image & border-image https://developer.mozilla.org/en-US/docs/Web/CS ...

  5. H5 下拉刷新、加载更多

    H5 下拉刷新.加载更多 demos const autoLoadMore = (url = ``) => { // todo ... } refs xgqfrms 2012-2020 www. ...

  6. robots.txt

    robots.txt A robots.txt file tells search engine crawlers which pages or files the crawler can or ca ...

  7. input change only trigger once bug

    input change only trigger once bug clear first https://stackoverflow.com/a/11280934/5934465 upload E ...

  8. Apache 低版本不支持 WebSocket

    Apache 低版本不支持 WebSocket Apache HTTP Server Version 2.4 Apache Module mod_proxy_wstunnel https://http ...

  9. 「NGK每日快讯」2021.2.11日NGK公链第100期官方快讯!

  10. DeFi里的灰度?每月获得高收益?BGV代币初探

    2020年已经接近了尾声,但是DeFi市场的热闹场面并没有停止,或者说,一直在延续.资本市场不断将大批的资金投入到DeFi市场中,以求在这波热潮中赚得一波又一波红利. 美国时间12月21日,Bacca ...