zoukankan      html  css  js  c++  java
  • 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





  • 相关阅读:
    html+css动态篇
    html+css定位篇
    首页的css
    display详细说明
    html+css 布局篇
    html+css杂记
    JS与ES的关系
    H5本地存储
    JavaScript面向对象
    JavaScript执行上下文
  • 原文地址:https://www.cnblogs.com/DirWang/p/11430768.html
Copyright © 2011-2022 走看看