Improve encode_nix32 comment

This commit is contained in:
Artemis Tosini 2024-07-18 21:19:43 +00:00
parent 60323508d6
commit f3a998037a
Signed by: artemist
GPG key ID: EE5227935FE3FF18

View file

@ -614,17 +614,26 @@ fn encode_nix32(input: &[u8]) -> String {
// The output is backwards and bits are grouped
// from the least significant bit in each byte
// instead of the most significant bit.
// e.g. encoding "Meow" gives us:
// e.g. for a 4-byte input, bits are mapped from input to output like this:
// Out No.: 5 5 5 6 6 6 6 6 | 3 4 4 4 4 4 5 5 | 2 2 2 2 3 3 3 3 | 0 0 1 1 1 1 1 2
// Out Bit: 2 1 0 4 3 2 1 0 | 0 4 3 2 1 0 4 3 | 3 2 1 0 4 3 2 1 | 1 0 4 3 2 1 0 4
//
// where "Out No." is the index of the output charater responsible for a given bit;
// and "Out Bit" is the value of a given bit within the output character,
// with 4 being most significant and 0 being least significant.
//
// for "Meow" we'd get:
// Char: M (0x4d) e (0x65) o (0x6f) w (0x77)
// Value: 0 1 0 0 1 1 0 1 | 0 1 1 0 0 1 0 1 | 0 1 1 0 1 1 1 1 | 0 1 1 1 0 1 1 1
// Out No.: 5 5 5 6 6 6 6 6 | 3 4 4 4 4 4 5 5 | 2 2 2 2 3 3 3 3 | 0 0 1 1 1 1 1 2
// Out Bit: 2 1 0 4 3 2 1 0 | 0 5 4 3 2 1 4 3 | 3 2 1 0 4 3 2 1 | 1 0 4 3 2 1 0 4
//
// where "Out No." is the index of the output charater responsible for a given bit,
// and 2**"Out Bit" is the value of a given bit for its output character.
//
// In this example, characters 0 to 6 have values
// 0x01, 0x1b, 0x16, 0x1e, 0x19, 0xa, 0xd.
// Out Bit: 2 1 0 4 3 2 1 0 | 0 4 3 2 1 0 4 3 | 3 2 1 0 4 3 2 1 | 1 0 4 3 2 1 0 4
// 6: 01101 (0x0d)
// 5: 01010 (0x0a)
// 4: 11001 (0x19)
// 3: 11110 (0x1e)
// 2: 10110 (0x16)
// 1: 11011 (0x1b)
// 0: 00001 (0x01)
// Indexing into the alphabet gives us "1vnyrad"
for char_no in 0..length {