Cryptography

Encoding methods

Easy
10 min

What are Encoding Methods?

Encoding methods are rules or algorithms that convert data from one form to another. This transformation can be, for example, converting text into binary code in a format understandable by a computer, or compressing a digital image into a space-saving format. One of the most well-known examples is Base64 encoding, which converts binary data to ASCII text, allowing binary data to be included in, for example, email messages or web pages.

It is essential to note that encoding methods are not encryption methods. Their purpose is not to make the text any more protected or secret, only to present it in a different form.

Common encoding techniques

Base64

Base64 encoding is a widely used method for converting binary data into ASCII text. This process allows binary data to be transferred and stored in environments designed to handle only text data. Originally developed in the context of email messages, this method has become an essential tool in a wide range of digital world applications.

Base64 converts binary data into text consisting of 64 ASCII characters. This character set includes uppercase and lowercase English letters (A-Z, a-z), numbers (0-9) and two additional characters (+ and /). In addition, there is one special character ('=') used for padding, ensuring that the result is always divisible by four.

The process of Base64 encoding consists of the following steps:

  • Sharing Binary Data: Binary data is divided into 6-bit groups, as 64 possible values can be represented exactly with 6 bits.
  • Character Conversion: Each 6-bit group is converted to a corresponding character in the Base64 alphabet.
  • Padding: If the total length of the data is not divisible by three (three bytes = 24 bits), '=' characters are added to the end as padding until the length of the string is divisible by four.

Hex Encoding

Hexadecimal encoding, more commonly known as hex encoding, is an essential tool in digital technology, providing an efficient and clear way to represent binary data. This method, which is based on the 16-system, converts binary data into hexadecimal numbers using the numbers 0-9 as well as the letters A-F.

For example, when a hashing algorithm, such as SHA-256, produces a hash value, it is typically represented in hexadecimal format. This allows for complex binary data to be presented in a clear and compact form.

The SHA-256 hash value of the text "Hello World" could be A591A6D40BF420404A011733CFB7B190D62C65BF0BCDA32B57B277D9AD9F146E.

The popularity of hex encoding is based on its ability to provide a clear and concise way to represent binary data. It facilitates data processing, understanding, and debugging.

Exercise

Use CyberChef tool for this exercise. Hint: You will need both the "From hex" and "From base64" modules.

Convert the following value to the correct form using both encoding methods. "4e 44 67 67 4e 6a 55 67 4e 6d 4d 67 4e 6d 4d 67 4e 7a 55 67 4e 7a 49 67 4e 6a 55 67 4e 6a 6b 3d"

hakatemia pro

Ready to become an ethical hacker?
Start today.

As a member of Hakatemia you get unlimited access to Hakatemia modules, exercises and tools, and you get access to the Hakatemia Discord channel where you can ask for help from both instructors and other Hakatemia members.