Encoding n Decoding messages using Base64 and Caesar Box and coding it in different known languages(C , Java , GoLang , Python , Perl , Ruby , Assembly Language).

Lavish Garg
4 min readSep 11, 2019

What is Encoding?

The purpose of encoding is to transform data so that it can be properly (and safely) consumed by a different type of system, e.g. binary data being sent over email, or viewing special characters on a web page. The goal is not to keep information secret, but rather to ensure that it’s able to be properly consumed.

Encoding transforms data into another format using a scheme that is publicly available so that it can easily be reversed. It does not require a key as the only thing required to decode it is the algorithm that was used to encode it.

What is Decoding?

The reverse format of encoding is called decoding which is only be decrypted by that person who knows algorithm by which message is encoded.

Base64

Base64 is a group of 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.

Common to all binary-to-text encoding schemes, Base64 is designed to carry data stored in binary formats across channels that only reliably support text content. Base64 is particularly prevalent on the World Wide Web where its uses include the ability to embed image files or other binary assets inside textual assets such as HTML and CSS files.

Encoding messages using Base64

Concept

Base64 encoding breaks binary data into 6-bit segments of 3 full bytes and
represents those as printable characters in ASCII standard. It does that in essentially
two steps.

The first step is to break the binary string down into 6-bit blocks. Base64 only uses 6 bits (corresponding to 2⁶ = 64 characters) to ensure encoded data is printable and humanly readable. None of the special characters available in ASCII are used. The 64 characters (hence the name Base64) are 10 digits, 26 lowercase characters, 26 uppercase characters as well as the Plus sign (+) and the Forward Slash (/). There is also a 65th character known as a pad, which is the Equal sign (=). This character is used when the last segment of binary data doesn’t contain a full 6 bits.

Steps Wise Explanation

1. Take one example message “Love”.

2. Convert each letter into ASCII number using ASCII table.

3. After converting text the value will be “76 111 118 101”.

4. Now convert each value to 8 bit binary.

5. After converting to binary it will seems like this “01001100 01101111 01110110 01100101”.

6. Now make the pair of six-six number.

7. Six pair will seem like this “010011 000110 111101 110110 011001 010000”.

8. Bold zeroes means to make it 6 bit.

9. Now convert this six paired binary to decimal.

10. Decimal number will be like this “19 6 61 54 25 16”.

11. A pair of zeroes added in last to make number 6 bit is consider with ‘=’. Here we added four zeroes in last(bold color zeroes) so we consider two ‘==’ in last of our answer.

Using the Base64 table.

12. So your answer will be some what like this “TG92ZQ==”

13. Now for decoding reverse these steps.

Base64 code in different languages

1. Go Lang

2. C Programming

3. Java

4. Python

a) Encoding

b) Decoding

5. Ruby

6. Perl

7. Assembly Language

**Reference: Assembly code is from Ankur Saini GitHub account**

CAESAR BOX.

Julius Caesar was one of the first people to write in code. He invented the Caesar cipher, in which each letter is replaced with another letter that’s a fixed number of positions down the alphabet. The following cipher is not the Caesar cipher, but rather what cryptographers call a “columnar transposition cipher” or “Caesar’s Box” though it is unclear if the code was ever actually used by Caesar.

Step Wise Explanation For Encoding

1. We again take the example text “I LOVE YOU”.

2. Now remove all spaces ”ILOVEYOU”

3. Now count the number of letters here there are 8 letter.

4. Now create a matrix of any order like 4x2,2x4,((8x1,1x8) of no use).

5. We choose 4x2.

6. Now we arrange the letter in matrix form of order 4x2

I E

L Y

O O

V U

7. Now we write the letter from top to bottom (IELYOOVU)

8. So we get our encoded message.

9. To decode we again count the number of letters here 8 letters.

10. Again create the order of matrix 4x2,2x4.

11. We take matrix in inverted form like encode using 4x2 and decode it using 2x4.

12. You get your message decoded.

Thank You.

--

--

Lavish Garg

I write articles related to Cyber Security and Blockchain.