Base84 deserves a place in file names
Recorded: Sept. 13, 2026, 2:09 p.m.
| Original | Summarized |
Base84 deserves a place in file names - Frank DENIS random thoughts. Skip to main content Frank DENIS random thoughts. Archive Base84 deserves a place in file names September 9, 2026 The TurboCrypt file encryption tool was originally designed for Unix systems. That leaves 85. Every character is acceptable in a filename on the usual Linux, macOS and Windows filesystems. Encoding Base64 Base84 An input filled with 0xff forces every full group to consume only 31 bits. That’s the worst case: about 29% expansion. Related Posts Sep 09, 2026 Aug 19, 2026 Jul 30, 2026 Jul 16, 2026 Jul 08, 2026 ← Back to posts GitHub |
Frank DENIS proposes that Base84 should be incorporated into file naming conventions to ensure portability and compatibility across different operating system filesystems. This necessity arose because the initial implementation of the TurboCrypt file encryption tool, which utilized Base91 for encoding encrypted filenames, was constrained by the specific requirements of Unix and macOS systems. When expanding compatibility to Windows, where certain characters found in the Unix-filesystem-safe alphabet are forbidden, a change in encoding scheme was required. The rationale for adopting Base84 is rooted in the character set restrictions imposed by the Windows filesystem. While the standard printable ASCII set includes 94 characters excluding the space, Windows imposes specific restrictions that exclude nine characters, such as less-than signs, greater-than signs, colons, quotes, forward slashes, backslashes, pipes, question marks, asterisks, and the dot. Furthermore, dropping the dot is recommended for reliable interaction with the Windows shell and ordinary file APIs. This adjustment reduces the available character set to 84 potentially usable characters for a filename component. The implementation details of Base84, as seen in the zig-base84 library, focus on efficient bit packing. The encoder groups the encoded data into sets of five characters, a choice determined by an optimization where 84 to the power of five is used, yielding a result close to 4.18 billion, which offers sufficient room for approximately 32 bits of information. For random input, the packing results in an average expansion rate of approximately 25.2% compared to the binary input, positioning it as slightly more efficient than Base64, with a worst-case expansion rate reaching about 29.0% when the input is entirely composed of the maximum value 0xff. The practical application of Base84 also addresses filesystem size limits. Since most filesystems restrict names to a maximum of 255 bytes, and the Base84 alphabet size (84) is a divisor of 255, the encoding naturally fits perfectly into whole groups without losing information due to partial groups. This method guarantees room for approximately 197 bytes of input, which is an improvement over the 191 bytes suggested by unpadded Base64. This feature provides a robust method for handling filenames within established filesystem constraints. When considering Unix-only filenames, a specialized variant of Base91 exists where the slash character is replaced by an apostrophe. This variant offers a packing efficiency of approximately 6.51 bits per character for random input, resulting in a roughly 23% expansion. Moreover, the structure imposed by the five-character packing has an important side effect concerning reserved device names. Because the encoding scheme constrains the possible characters at the end of the encoded string, it is impossible to spell reserved device names like CON, NUL, COM1, or LPT1 through LPT9, regardless of case, by restricting the final characters to a specific range. This inherent property eliminates the need for additional special handling or padding to avoid these reserved names. |