• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Dawn_whisper
博客园    首页    新随笔    联系   管理    订阅  订阅

Python3中的编码转换大全(不定期更新)

Python3编码转换大全

进制转换

其他进制转十进制

2 -> 10
int('1100',2)
12
8 -> 10
int('1100',8)
576
16 -> 10
int('1100',16)
4352

十进制转其他进制

10 -> 2
bin(170)
'0b10101010'
10 - > 8
oct(170)
'0o252'
10 -> 16
hex(170)
'0xaa'

Html编码

import html
html.unescape('&#102')
'f'

当然也可以多个字符

import html
html.unescape('flag')
'flag'

Base编码

加密

base64
import base64
a=b'233'
b=base64.b64encode(a)
b
b'MjMz'

base32
import base64
a=b'233'
b=base64.b32encode(a)
b
b'GIZTG==='

base16
import base64
a=b'233'
b=base64.b16encode(a)
b
b'323333'

解码

base64
import base64
a=b'MjMz'
b=base64.b64encode(a)
b
b'233'

base32
import base64
a=b'GIZTG==='
b=base64.b32decode(a)
b
b'233'
base16
import base64
a=b'323333'
b=base64.b16decode(a)
b
b'233'

至于base58

这个因为比较晚,所以在另外一个库base58里

编码
import base58
a=b'233'
b=base58.b58encode(a)
b
b'HryY'
解码
import base58
a=b'HryY'
b=base58.b58encode(a)
b
b'233'
posted @ 2019-09-18 21:37  Dawn_whisper  阅读(523)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3