A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
A-Z
和数字 2-7
)对任意字节数据进行编码的方案,编码后的字符串不用区分大小写并排除了容易混淆的字符,可以方便地由人类使用并由计算机处理。Base32 比 Base16 占用的空间更小(1000 比特数据 Base32 需要 200 个字符,而 Base16 则为 250 个字符)。
-bash/zsh: base32 command not found #Debian apt-get install coreutils #Ubuntu apt-get install coreutils #Alpine apk add coreutils #Arch Linux pacman -S coreutils #Kali Linux apt-get install coreutils #CentOS yum install coreutils #Fedora dnf install coreutils #OS X brew install coreutils #Raspbian apt-get install coreutils #Docker docker run cmd.cat/base32 base32
base32 编码旨在以需要不区分大小写但不需要人类可读的形式,表示任意八位字节序列。
base32 编码的数据比原始数据大 60% 左右,Base32 另外一个缺点,是生成的字符串比 Base64 长约 20%,因为 Base32 使用 8 个 ASCII 字符去编码原数据中的 5 个字节数据,而 Base64 是使用 4 个 ASCII 字符去编码原数据中的 3 个字节数据。
base32 数据按照 RFC 4648 中 base64 字母表的描述进行编码。这使用字母表 AZ,后跟 2-7。由于与字母 O、I、B 和 G 的相似性,跳过了 0、1、8 和 9 ..当输入组中可用的输入位少于 40 个时,值为零的位将被添加(在右侧)以形成整数个 5 位组。数据末尾的填充使用 = 字符执行。
base32 解码时,除了正式 base64 字母表的字节外,输入还可能包含换行符。可以使用 --ignore-garbage
尝试从编码流中的任何其他非字母字节中恢复。
base32 是 coreutils(基本文件、Shell 和文本操作实用程序)项目的一部分,其优点如下:
值 | 符号 | 值 | 符号 | 值 | 符号 | 值 | 符号 | |||
---|---|---|---|---|---|---|---|---|---|---|
0 | A | 8 | I | 16 | Q | 24 | Y | |||
1 | B | 9 | J | 17 | R | 25 | Z | |||
2 | C | 10 | K | 18 | S | 26 | 2 | |||
3 | D | 11 | L | 19 | T | 27 | 3 | |||
4 | E | 12 | M | 20 | U | 28 | 4 | |||
5 | F | 13 | N | 21 | V | 29 | 5 | |||
6 | G | 14 | O | 22 | W | 30 | 6 | |||
7 | H | 15 | P | 23 | X | 31 | 7 | |||
填充 | = |
由于数据的二进制传输是按照8比特一组进行(即一个字节),因此 Base32 按 5 比特切分的二进制数据必须是 40 比特的倍数(5 和 8 的最小公倍数)。例如输入单字节字符 %,它对应的二进制值是 100101,前面补两个 0 变成 00100101(二进制值不足8比特的都要在高位加 0 直到 8 比特),从左侧开始按照5比特切分成两组:00100 和 101,后一组不足 5 比特,则在末尾填充 0 直到 5 比特,变成 00100 和 10100,这两组二进制数分别转换成十进制数,通过上述表格即可找到其对应的可打印字符 E 和 U,但是这里只用到两组共 10 比特,还差 30 比特达到 40 比特,按照 5 比特一组还需 6 组,则在末尾填充 6 个 =。填充 = 符号的作用是方便一些程序的标准化运行,大多数情况下不添加也无关紧要,而且,在URL中使用时必须去掉 = 符号。
base32 [OPTION]... [FILE]
Base32 encode or decode FILE, or standard input, to standard output. With no FILE, or when FILE is -, read standard input. Mandatory arguments to long options are mandatory for short options too. -d, --decode decode data -i, --ignore-garbage when decoding, ignore non-alphabet characters -w, --wrap=COLS wrap encoded lines after COLS character (default 76). Use 0 to disable line wrapping --help display this help and exit --version output version information and exit The data are encoded as described for the base32 alphabet in RFC 4648. When decoding, the input may contain newlines in addition to the bytes of the formal base32 alphabet. Use --ignore-garbage to attempt to recover from any other non-alphabet bytes in the encoded stream.
目标文件
base32 基本的 echo 和 piping 管道示例(base32 编码 / 解码):
$ echo 'this is some text I want to encode' | base32 ORUGS4ZANFZSA43PNVSSA5DFPB2CASJAO5QW45BAORXSAZLOMNXWIZIK ---------------- $ echo 'ORUGS4ZANFZSA43PNVSSA5DFPB2CASJAO5QW45BAORXSAZLOMNXWIZIK' | base32 -d this is some text I want to encode
base32 编码文件:
base32 filename
base32 解码文件:
base32 -d filename
base32 从标准输入编码:
somecommand | base32
base32 从标准输入解码:
somecommand | base32 -d