Python simply implements the encoding and decoding methods of Base64

  • 2020-05-30 20:31:10
  • OfStack

This article illustrates a simple Python implementation of Base64 encoding and decoding. I will share it with you for your reference as follows:

Base64 code is a kind of "guard against the gentleman but not against the villain" code. Widely used in the MIME protocol, as the transmission encoding of E-mail, the generated encoding is reversible, the last two may have "=", and the generated encoding is ascii characters.

Advantages: fast speed, ascii characters, unreadable to the naked eye

Disadvantages: the code is long, very easy to crack, only used to encrypt non-critical information

Example encoding and decoding of Python Base64:


>>> import base64
>>> s = ' I'm a string '
>>> a = base64.b64encode(s)
>>> print a
ztLKx9fWt/u0rg==
>>> print base64.b64decode(a)
 I'm a string 

PS: here are a few more practical base64 online coding and decoding tools for you to use:

BASE64 encoding and decoding tools:
http://tools.ofstack.com/transcoding/base64

Online image conversion BASE64 tool:
http://tools.ofstack.com/transcoding/img2base64

Base64 online encoding and decoding UTF-8:
http://tools.ofstack.com/tools/base64_decode-utf8.php

Base64 online encoding and decoding gb2312:
http://tools.ofstack.com/tools/base64_decode-gb2312.php

More about Python related content interested readers to view this site project: Python coding skills summary, Python pictures skills summary, "Python data structure and algorithm tutorial", "Python Socket programming skills summary", "Python function using techniques", "Python string skills summary", "Python introduction and advanced tutorial" and "Python file and directory skills summary"

I hope this article is helpful to you Python programming.


Related articles: