How to create encoding and decoding Base64 using PYTHON
What Will I Learn?
- Why Python ?
- What is Base64 ?
- How to encode base64 with Python
- How to decode base64 with Python
Requirements
- You have a basic knowledge of PYTHON
- You have already installed PYTHON 2
- Text Editor
Difficulty
- Intermediate
Tutorial Contents
Why Python ?
Python is a programming language that is easy to learn and powerful. Python has an efficient high-level data structure and approach to simple but effective object-oriented programming (OOP). elegant python syntax and typing dynamics, together with its interpreted nature, make python an ideal language for scripting programming and rapid application development in various fields and almost all platforms.
Python is one of high-level programming language that is intrepreter, interactive, object oriented and can operate on almost any platform, such as UNIX family, Mac, Windows, OS / 2, or other.as a high-python high language including one of the programming languages which is easy to learn because of its clear and elegant syntax, combined with the use of ready-to-use modules and efficient high-level data structures.
What is Base64 ?
Base64 is a method used to encoding binary data so that it becomes "printable" or in short binary data is encoded into a 7-bit character format such as part of the email content.
I will only explain the basic meaning of a base64, because if we explain it will be very long or you can also read it complete on Wikipedia http://en.wikipedia.org/wiki/Base64.
So, essentially Base64 is a code composed by 64 characters, whose character (based on: RFC 1421) consists of (A-Z, a-z, 0-9, +, /) or "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 + /". But there is one extra character that is "=", whose function is to fulfill or term it as a filler pad.
So you are not confused to learn about encode and decode base64 using python, let's follow my steps as follows:
As we know, to start python coding, you have to install python version 2 application. After you install open
COMMAND PROMT
orCMD
if you useWINDOWS
, because the author usesWindows
then to start it is usingCMD
orCommand Promt
or you can follow my steps like this:
Step 1 : Select Start Windows
Step 2 : Choose All Programs
Step 3 : Then find the Python folder, Here the author uses Python 2.7
Step 4 : Next click on the Python folder, then select Python (command line).
After that it will appear Python command line, as follows:
After following the steps as above, then next we will make encode and decode base64.
As we know that the activity of encode and decode is to secure the secret writing and reading the writings that are confidential, therefore the author wants to make the writing to be encoded and decoded with base64 is:
encode : tutorialencodedandecodebase64withpython
decode : dHV0b3JpYWxlbmNvZGVkYW5kZWNvZGViYXNlNjR3aXRocHl0aG9u
encode base64
Type this script in the command line to encode "tutorialencodedandecodebase64withpython"
import base64
data = base64.b64encode("tutorialencodedandecodebase64withpython")
- after then type the variable "data" without any quotes to display the writing that has been encoded as below:
data
That is the result of the writing we have encoded earlier. dHV0b3JpYWxlbmNvZGVkYW5kZWNvZGViYXNlNjR3aXRocHl0aG9u
The next step is, how to decode writing that has been encoded earlier.
decode base64
Type this script in the command line to decode
"dHV0b3JpYWxlbmNvZGVkYW5kZWNvZGViYXNlNjR3aXRocHl0aG9u "to do the same decode as well as the first step, just change the syntax encode to decode see the following syntax :
data = base64.b64decode("dHV0b3JpYWxlbmNvZGVkYW5kZWNvZGViYXNlNjR3aXRocHl0aG9u")
- after then type the variable "data" without any quotes to display the writing that has been decode as below:
data
After we do the decode then out the posts we have encode earlier that is : tutorialencodedandecodebase64withpython
FULL SYNTAX PYTHON ENCODE DAN DECODE BASE64
Thank You Utopian-io for giving me the opportunity to share tutorials or information about python about encode and decode.
Hopefully useful for you all.
Posted on Utopian.io - Rewarding Open Source Contributors
Your contribution cannot be approved because it does not follow the Utopian Rules.
Screenshots are from 2016, the tutorial isn't informative and very trivial.
You can contact us on Discord.
[utopian-moderator]