playing with formatting

Peter Harpending 2025-03-23 14:21:55 -07:00
parent ef7c6be734
commit 4b2b519ead

@ -2,7 +2,7 @@
![BaseN diagram](./uploads/baseN-thumb-original-1024x576.png)
## Quick Reference
# Quick Reference
1. Original article: <https://zxq9.com/archives/2688>
2. Base64 Erlang:
@ -14,70 +14,56 @@
5. Base58 TypeScript:
<https://github.com/aeternity/Vanillae/blob/829dd2930ff20ea0473cf2ad562e0a1c2aba0411/bindings/typescript/src/b58.ts>
## tl;dr
# tl;dr
Base64 and Base58 are two schema for taking binary data and encoding it
to and from plain text.
1. Conceptually:
1. These are **NOT** two instances of a general "base N" concept.
2. Base64 thinks of the binary data as a long stream of bytes.
Base64 converts bytes to/from text 3 bytes at a time in a
"fire-and-forget" manner.
3. Base58 thinks of the binary data as a really really long
integer.
Base58 requires processing the entire bytestring all at once as
a singular unit.
4. Base58 *is* the general BaseN algorithm. Base64 is simpler
because 64 and 256 are both powers of 2 and computers use
binary.
2. Terminologically:
1. The terms "encode" and "decode" are meant *from the perspective
of the computer program*. From the program's perspective, binary
data is what makes sense and plain text is gobbletygook. So
1. we *decode* plain text (gahbage) into binary data (what
makes sense)
2. we *encode* binary data (what makes sense) to plain text
(gahbage)
3. Practically:
1. Almost every language (including Erlang) has base64 in its
standard library, and you should probably just use that.
2. You probably have to code Base58 yourself.
3. If you are implementing Base58 in a language that does not have
bignum arithmetic, you have to implement it yourself. Thankfully
nobody will ever need any language other than Erlang so we can
ignore this problem in the context of this wiki.
4. Base58 is *super* inefficient both space-wise and time-wise, because it
requires processing the entirety of the binary string as a single
monolithic piece of data.
5. Base58 exists to preempt `Il10O`-type problems (visual
ambiguity) and doesn't involve `=+/` characters (the idea being
email clients are likely to break long lines at these
characters, increasing the likelihood of input errors).
6. Consequently, Base58 is only suitable for binary data that is
**both**
1. short in length
2. likely to be entered manually (e.g. wallet/contract
addresses)
# Base64
The term "binary" is misleading, because it leads people to think that
@ -243,7 +229,7 @@ This is marginally trickier because
### Base64 Alphabet
``` {.Erlang language="Erlang"}
```erlang
int2char( 0) -> $A;
int2char( 1) -> $B;
int2char( 2) -> $C;