Communicating in secret language with the trusted ones is so much fun, right? Let me show you something interesting. It could be a starting point for you to begin your journey in **Cryptography**.

# Magic:

Thread-2 Conclusion: Function overloading isnotpossible in python.https://www.geeksforgeeks.org/python-method-overloading/

# How did you do that?

These encoding form the bread, butter, and jam for Information Security. Let’s get into each one, one at a time.

## Hex code:

Hex code is the simplest form of encoding. Hex encoding works on 16 (=2⁴) characters *0* through *9* and *a* through *f*.

0x 0 = 0b 0000 (0x = hexadecimal, 0b = binary)

0x 1 = 0b 0001

0x 2 = 0b 0010

…

0x 9 = 0b 1001

0x a = 0b 1010

…

0x f = 0b 1000

0x 10 = 0b 0001 0000

…

To decode, a hex code into ASCII text:

- Convert each hex character to its corresponding 4-bit binary form.
- Consider groups of 8-bits starting from the most significant bit (leftmost bit), and convert them into corresponding ASCII value.
- As an intermediate step, you may convert the group of 8-bits to decimal and then map it to its ASCII character.

Let us do some raw decoding, in line with the above algorithm:

Since, one hex character decodes to 4-bit binary and in the consequent step 8-bit binary ( 4 x 2 = 8) is considered as a group, this algorithm decodes the hex code to ASCII by considering two hex characters every iteration.

Python makes life easy:

## Base64:

64! Doesn’t this number sound familiar? That’s right, it is also a perfect power of 2 (2⁶ = 64).

On the other hand, observe that 0–9 counts 10, A-Z counts to 26, and a-z counts to another 26. This totals to 62.

Too close! To make it up to 64, the base 64 standards use + and /.

Of all the symbols on the keyboard, why only + and /?

+ and / are two of the symbols which are unaffected by URL encoding.

Long story short, binary files are encoded in base64 format before network communication through browser. This way, a host can send 64 bits (actual binary) in 8 bits (base64 character).

To decode a base64 encoded text into binary:

- Load the base64 table.
- Reverse lookup each character and convert the decimal to its corresponding 6-bit binary.
- Replace the trailing ‘=’ with exactly 2 zeros (these are called padding characters).
- Verify that the total number of bits is divisible by 8.

Further, convert the 8-bit group to the corresponding ASCII character to view the message.

Try coding *gimme_plain_text_from_base64* function by yourself. I hope this is interesting. More of this to come, so stay tuned!