Tutorial Encoding and Decoding Base64 with Python on Linux

in #utopian-io7 years ago (edited)

What Will I Learn?

  • What is Python ?
  • What is Base64 ?
  • How to encode base64 with Python on Linux
  • How to decode base64 with Python on Linux

Requirements

  • You have a basic knowledge of Python
  • Linux Operating System
  • Command Line or Terminal
  • Text Editor

Difficulty

  • Intermediate

Tutorial Contents

- What is Python ?

Python is a multipurpose interpretative programming language. with a design philosophy that focuses on the legibility of the code. Python is claimed to be a language that combines capabilities, capabilities, with very clear code syntax, and comes with a large and comprehensive standard library functionality.

- 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.

Basically 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 additional 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 programming we have to go into python shell, To start we have to open Terminal. Follow my steps as below :
  1. Open terminal (Ctrl + Alt + T)
  2. Type python then you will go into sheel Python.
The author here uses linux times for the operating system and still uses python version 2.7 and last update in 2017.

Screenshot from 2018-02-01 13-49-58.png

Screenshot from 2018-02-01 13-50-20.png

  • Once we get into the python shell, then the next step we start encoding and decoding base64 on python.

  • And the author will do the encoding and decoding the writing as below :

encoding : "encodinganddecodingbase64dilinux"

decoding : "ZW5jb2RpbmdkYW5kZWNvZGluZ2Jhc2U2NGRpbGludXg="

Encoding Base64

  • To start the first step ie encoding then type the script or command like below :

     import base64
     encoding = base64.b64encode("encodinganddecodingbase64dilinux")

Screenshot from 2018-02-01 14-06-16.png

  • Next type "encoding" to view encrypted secreted posts :

    encoding

Screenshot from 2018-02-01 15-11-37.png

  • After we do "encode" in the words "encodinganddecodingbase64dilinux" then it becomes like = "ZW5jb2RpbmdkYW5kZWNvZGluZ2Jhc2U2NGRpbGludXg=".

Decoding Base64

  • As we know, after we do the "encoding" we will definitely do the name "decoding" or the reversal of another word, that is to break the writing of a secret or crack the password that has been in "encode".

  • To do "decoding" you do not need to open another "Terminal", you simply write the script or direct command under it. Follow my steps :

  • Type the following command :


   decoding = base64.b64decode("ZW5jb2RpbmdkYW5kZWNvZGluZ2Jhc2U2NGRpbGludXg=")

Screenshot from 2018-02-01 15-28-20.png

  • Next type "decoding" to see the posts that are encoded in secret :

   decoding 

Screenshot from 2018-02-01 15-30-50.png

After we do the decode then out the posts we have encode earlier that is: encodinganddecodingbase64dilinux

FULL SCRIPT OR SYNTAX

Screenshot from 2018-02-01 15-34-46.png

The author here uses kali linux for the operating system and still uses python version 2.7 and last update in 2017.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Your contribution cannot be approved because it does not follow the Utopian Rules.

You already posted about this before here, where I already told you the tutorial was too trivial to be considered a valid contribution to Utopian.io.

You can contact us on Discord.
[utopian-moderator]