Weekly letter pythonprogramming.email
Hi,
To get the curated list of awesome python articles from all over the Internet, please subscribe with pythonprogramming.email. This is specifically suitable for beginners.
Advertise with us
Base64 Encode Decode
  


Python Code
As per Wikipedia:
Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The term Base64 originates from a specific MIME content transfer encoding. Each base64 digit represents exactly 6 bits of data. Three 8-bit bytes (i.e., a total of 24 bits) can therefore be represented by four 6-bit base64 digits.

To convert a string in base64 format use below python code:

import base64


text = "pythoncircle.com"
result = base64.b64encode(bytes(text, "utf-8")).decode("ascii")
print(result)

To decode a base64 encoded text into plain text, use below python code:

text = "cHl0aG9uY2lyY2xlLmNvbQ=="
try:
    result = base64.b64decode(bytes(text, "utf-8")).decode("ascii")
    print(result)
except TypeError:
    print("Data not in specified format.")
except:
    print("Conversion not possible.")



SUBSCRIBE
Please subscribe to get the latest articles in your mailbox.

© 2017-2020 Python Circle   Contact   Sponsor   Archive   Sitemap