当前位置:网站首页>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
边栏推荐
- [untitled] leetcode 2321 Maximum score of concatenated array
- Why can't programmers who can only program become excellent developers?
- 【C语言】详解指针的初阶和进阶以及注意点(1)
- STM32 standard firmware library function name (I)
- Kityformula editor configure font size and spacing
- CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
- Find the maximum inscribed circle of the contour
- 871. 最低加油次数 : 简单优先队列(堆)贪心题
- Why can't browsers read JSX?
- Some Chinese character codes in the user privacy agreement are not standardized, which leads to the display of garbled codes on the web page. It needs to be found and handled uniformly
猜你喜欢

C language exercises - (array)
![[noi simulation] Elis (greedy, simulation)](/img/a2/f8c8ab3bc8dd779327be3f76990976.png)
[noi simulation] Elis (greedy, simulation)

Yolov6 training: various problems encountered in training your dataset

Introduction to mathjax (web display of mathematical formulas, vector)

geoserver离线地图服务搭建和图层发布

【apipost】使用教程

taobao.trade.memo.add( 对一笔交易添加备注 )接口,淘宝店铺插旗接口,淘宝订单插旗API接口,oAuth2.0接口

大顶堆、小顶堆与堆排序

表格响应式布局小技巧

实用调试技巧
随机推荐
Edit the formula with MathType, and set it to include only mathjax syntax when copying and pasting
[QNX Hypervisor 2.2用户手册]6.3 Guest与外部之间通信
mathML转latex
LeetCode 209. 长度最小的子数组
一张图彻底掌握prototype、__proto__、constructor之前的关系(JS原型、原型链)
天猫商品详情接口(APP,H5端)
C#代码审计实战+前置知识
Ad20 cannot select the solution of component packaging in PCB editor
qml 弹窗框架,可定制
fatal: unsafe repository is owned by someone else 的解决方法
LeetCode 209. Minimum length subarray
.NET Core 日志系统
解决el-radio-group 回显后不能编辑问题
【NOI模拟赛】伊莉斯elis(贪心,模拟)
Points clés de l'examen de principe de compilation pour l'année scolaire 2021 - 2022 [Université chinoise d'outre - mer]
Solve the problem that El radio group cannot be edited after echo
Bit by bit of OpenCV calling USB camera
PTA question bank== > complex four operations, one for one, examination seat number (7-73)
为什么只会编程的程序员无法成为优秀的开发者?
taobao. trades. sold. Get query the transaction data that the seller has sold (according to the creation time), Taobao store sales order query API interface, Taobao R2 interface, Taobao oauth2.0 trans
