当前位置:网站首页>Base64 coding can be understood this way
Base64 coding can be understood this way
2022-07-02 15:03:00 【zx_ twenty million two hundred and twenty thousand one hundred 】
Worked as a programmer for four years , Frequently used Base64 code , But why use , And how it works , It has always been without understanding . I saw it in a book recently Base64 The coding principle of , It turned out to be so simple .
Base64 What problems have been solved
If we want to transmit the following problems in the network
Hello Children I'm brick family who are you ? This text contains spaces 、 Line break 、 Invisible characters such as carriage return , In network transmission , Each device may have different processing mechanisms for invisible characters , There will be information transmission errors . At this point, we need a coding mechanism , Turn all invisible characters into visible characters .
Base64 Coding principle
Next, we will pass abcd Two words turn into Base64 code , To understand its principle .
Group the characters into three groups , Not enough time to pass 0 A filling . such as abc Three characters in a group ,d Not enough for three , adopt 0 Complete as d00

2. Convert characters into binary ASCII code

3. Convert the converted binary , Separate every six digits

Q: Why does the first step need to be divided into three characters ?
A: because ASCII Code each character is 8 Bit binary ,3 * 8 = 24. It can be divided into 4 individual 6 Bit binary ,4 * 6 = 24.
6 Bit binary can represent 0-63, We have a rainbow watch , Can be 0-63 Each corresponds to a character , The rainbow table is as follows :

Through the rainbow table , We can put every 6 The binary after bit division is converted

It should be noted that , Where filling occurs 0, Need to use = To express . So the last two are =
Last abcd Convert to Base64 After coding is YWJjZA==, The overall principle is relatively simple , It doesn't involve sophisticated algorithms .
Base64 periphery
because Base64 Transcoding will include +/= character , stay URL Unable to transmit normally . So there is a kind of URL Friendly Base64 code , It exists and is used _- Instead of +/, And do not add =
Base32、Base16 Principle and Base64 Almost the same
Base64 Not suitable for encryption , Because decryption is too simple
Chinese characters pass gb2312、utf-8、gbk After the coding , It can be converted to binary processing . Here is a picture description on the Internet :

Base58 And Base58Check
Base58 It is a coding form used by bitcoin when generating wallet address . It and Base64 The main difference is to remove the characters that are easy to be mistaken by the naked eye 0( zero )、O( Capital O)、I( Capital i)、l( Lowercase letters L) And several characters that affect the double-click selection :/ and + The purpose of this coding is relatively simple , Is to prevent transfer , Read the wrong account , Transfer to wrong account .Base58 The principle of is simpler , It only involves the conversion of Radix , The general steps are as follows :
Convert characters to ASCII code
take ASCII Code to 58 Base number
Through rainbow table mapping
such as abcd transformation :
Turn into ASCII code 97-98-99-100
convert to 58 Base number 3-28-21-49-5-22
Map to 3VNr6P

Base58Check code , As the name suggests, it can be right Base58 Code to check . For example, I am transmitting qH912cvztx When coding , If the network is abnormal and other reasons , Cause data disorder or loss , The receiver should be able to recognize that there is a problem with the data .Base58Check The basic principle of coding is as follows :
stay data Add a version ID in front prefix, Used to identify the encoded data type , For example, the prefix of bitcoin address is 0( Hex is 0x00)
adopt hash Algorithm calculation prefix + data Of hash value :SHA256(prefix + data)
The generated hash The value is truncated to the first four digits , Splice back prefix + data + 4 position hash
Carry out the result generated in the previous step Base58 Coding calculation , Get the final result
边栏推荐
- [QNX hypervisor 2.2 user manual]6.3 communication between guest and external
- 复用和分用
- It's no exaggeration to say that this is the most user-friendly basic tutorial of pytest I've ever seen
- CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
- Introduction to mathjax (web display of mathematical formulas, vector)
- Error: NPM warn config global ` --global`, `--local` are deprecated Use `--location=global` instead.
- PTA question bank== > complex four operations, one for one, examination seat number (7-73)
- mathML转latex
- 实现一个多进程并发的服务器
- c语言入门--数组
猜你喜欢

Socket and socket address

JMeter script parameterization

obsidian安装第三方插件——无法加载插件

socket(套接字)与socket地址

【C语音】详解指针进阶和注意点(2)

关于网页中的文本选择以及统计选中文本长度

一张图彻底掌握prototype、__proto__、constructor之前的关系(JS原型、原型链)

使用mathtype编辑公式,复制粘贴时设置成仅包含mathjax语法的公式

Implement a server with multi process concurrency

taobao. trade. memo. Add (add remarks to a transaction) interface, Taobao store flag insertion interface, Taobao order flag insertion API interface, oauth2.0 interface
随机推荐
Full of knowledge points, how to use JMeter to generate encrypted data and write it to the database? Don't collect it quickly
info [email protected]: The platform “win32“ is incompatible with this module.
jmeter脚本参数化
CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
C语言习题---(数组)
LeetCode 2310. The number of digits is the sum of integers of K
tmall. product. schema. Get (product information acquisition schema acquisition), Taobao store upload commodity API interface, Taobao commodity publishing interface, Taobao commodity upload API interf
Bit by bit of OpenCV calling USB camera
YoloV6训练:训练自己数据集遇到的各种问题
MFC console printing, pop-up dialog box
2021-2022学年编译原理考试重点[华侨大学]
SQL 后计算的利器 SPL
AtCoder Beginner Contest 254
记一次报错解决经历依赖重复
为什么只会编程的程序员无法成为优秀的开发者?
mathjax 入门(web显示数学公式,矢量的)
【apipost】使用教程
taobao. trade. Get (get some information of a single transaction), Taobao store order interface, Taobao oauth2.0 interface, Taobao R2 interface code docking and sharing
Kityformula editor configure font size and spacing
C语言中的printf函数和scanf函数
