Bootstrap

python encode函数_python_base64和encode函数

对于python来说,base64加密与解密,有一个专门的函数供我们使用:

base64库

加密为:base64.b64encode()

解密为:base64.b64decode()

具体例子:

import base64 #导入base64库

s='最强近战单位SCV'

b=bytes(s,'utf-8') #将s的类型转化为bytes类型

c=base64.b64encode(b) #base64加密

print(c)

1

image-20200904160459371.png

解密代码:

import base64 #导入base64库

s='5pyA5by66L+R5oiY5Y2V5L2NU0NW'

b=bytes(s,'utf-8')

c=base64.b64decode(b) #解密

print(c) #直接输出c

print( )

print(c.decode()) #将c按照字符串输出

1

image-20200904161512633.png

上面提到了encode函数:

str_1="翔鹤太太"

str_2= "shoukaku&ladylex"

print(str_1.encode('utf-8'))

print(str_2.encode('utf-8'))

1

image-20200904164419393.png

;