Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the encoding / decoding algorithm of block chain hexadecimal data

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of the coding / decoding algorithm of block chain hexadecimal data, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article about the encoding / decoding algorithm of block chain hexadecimal data. Let's take a look.

As we all know, computers store and process binary data. For the sake of brevity, it is actually a variation of binary, hexadecimal, that is most commonly used. For example, the author's name is Jiawen, Chinese Pinyin is jiawen (all lowercase), and what is stored in the computer is 6A696177656E.

Obviously, it is easy for humans to remember jiawen, and its corresponding hexadecimal code 6A696177656E tests people's memory. Similarly, it is difficult for humans to remember hexadecimal data, but hexadecimal encoded text strings are relatively easy to remember and read. The following is part of a table of ASCII codes.

Hexadecimal 07 is a Bell (ringing). If you try to print it with a computer program, the result is invisible and incomprehensible, and only one ringtone can be heard. But the text string "07" is relatively easy to understand and remember. As mentioned above, Bitcoin addresses are hexadecimal numbers, without conversion, printing words are meaningless, human beings can not intuitively identify.

You can imagine the scene of querying the balance of your bank account. If there is only 77 yuan in the account, the query result will be printed as an uppercase character M (the decimal code is 77). I'm sure most users don't know that it means 77. On the other hand, if the number 77 is converted into the text "77" (its hexadecimal code is 3737) and then printed, the user will understand the text 77 displayed on the screen. To sum up:

The following sections discuss several encoding methods for representing hexadecimal data in text.

1 、 Base64

This is a 64 characters to represent any binary data method, usually exe, jpg, pdf and other files are binary files, open with a text editor is garbled, then you need a method, you can encode the binary into a string format, so you can open the binary file with text to view.

So, since it is BASE64, it is encoded by 64 characters, which 64 characters exactly? Please see the following table:

Base64 coding is mainly used in transmission, storage, presentation binary and other fields, and can also be used for encryption, but this kind of encryption is relatively simple, but it just seems to know nothing at first glance. Of course, you can also customize the character sequence of Base64 to encrypt. Let's take a look at the coding process of Base64.

First of all, since it is represented by the above range of 64 characters, it is necessary to use at least 6 bit to be able to represent various combinations of 64 characters. according to the permutation and combination, 6 bit can represent a total of 2 to the 6th power of the combination of characters. For a binary file that needs to be converted, it can be handled like this, every 3 bytes in a group, so that a total of 24bit, then can be divided into four groups, divided into four groups of 6bit, then compared to the table above to find the corresponding characters on it, so it can be converted to base64, simple it.

So, what if it's not a multiple of 3 when it's divided into 3 bytes? This requires the use of\ x00 bytes at the end, and one or two = signs at the end of the encoding to indicate how many bytes have been filled.

Since the characters + and / may appear after the standard Base64 encoding, they cannot be directly used as parameters in URL, so there is another "url safe" base64 encoding, which turns the characters + and / into-and _, respectively.

According to this principle, in fact, it is relatively easy to understand this kind of coding idea, and, you can also see that this kind of coding can be reversed. Take the string "yes" as an example, its Base64 coding is eWVz. You can try a few examples by yourself.

2 、 Base58

As the name implies, Base58 is based on 58 letters and numbers. With the foundation of Base64, it is easier for us to understand Base58, which is actually a subset of Base64. Compared to Base64, Base58 does not include the following Base64 characters:

The number 0

Capital letter O

Capital letter I

Lowercase letter l

+ and /

As you can see, lowercase o and uppercase O are easily confused with the number 0, and lowercase l and uppercase I are easily confused with the number 1. Base58 means that Base64 removes several characters that look confusing and / and + that can easily lead to escape. The coding table of Base58 is as follows:

123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz

It is important to note that different application implementations use the same coding table content, but the order may be different, such as:

1) Bitcoin address: 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz

2) Ripple address: rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz

Let's take a look at Base58Check, Bitcoin uses an improved version of the Base58 algorithm, in order to solve the problem that there is no integrity checking mechanism for Base58-encoded strings. In the process of propagation, if some characters are damaged or omitted, it can not be detected, so an improved version of the algorithm Base58Check is used.

3 、 Base58Check

In the process of binary data transmission, in order to prevent data transmission errors and protect data security, a check code is usually added. Through the cooperation of the check code, we can find out whether the data is corrupted or whether it was typed incorrectly when sending it. Base58Check is Base58 plus a check code, or a form of coding for Base58, which is used to generate wallet addresses in bitcoin systems.

We know that the wallet address is used for money transfer, although Base58 coding can avoid some easily confused characters, but there is no guarantee that the user's misinput or address information will be destroyed for some reason in the process of transmission, which will bring potential loss risk to the user.

The encoding method of Base58Check is as follows: before encoding, add a byte of version information to the content string to be encoded, and the version information can be agreed upon on its own. For example, the bitcoin address uses 0 × 00 as the version information, and then, ah, the hash value of the encoded content string is counted. Usually, you only need to get 4 bytes of the hash value, add it together, and then encode it as a whole.

In the process of generating a bitcoin address, the version byte is placed in the header, and the 4-byte hash value is placed at the end, and then encoded. This principle is still very simple, the hash algorithm has the inherent ability of data integrity detection, here we see another application of the hash algorithm.

If the encoded data is damaged or tampered with in the process of transmission, the receiver will calculate the same check code on the original data and compare it with the check code in the received result. Due to the characteristics of the hash algorithm, as long as there is any change in the original data, the calculated hash value will change, so as long as the check code is inconsistent, it means that the data is not legal.

This is the end of this article on "what is the encoding / decoding algorithm of block chain hexadecimal data". Thank you for reading! I believe that everyone has a certain understanding of the "block chain hexadecimal data encoding / decoding algorithm" knowledge, if you want to learn more knowledge, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report