The Universal Library is designed to contain every possible book of a given character set. It is inspired by Jorge Luis Borges' short story The Library of Babel, and the website of the same name. By containing every possible book, the library can contain every text that has been, or will ever be, written, as well as every slight variation and every book of gibberish. This program offers a way to retrieve any book from the enormous library, or to search the library for a book containing a certain text.
The character set used in this software extends that of the original Library of Babel, which uses 25 characters, and that of libraryofbabel.info, which uses 29 characters. Here. a set of 64 characters is used, and each book contains 2²⁰ characters. At 6 bits per character, each book represents 768KiB, and the library contains 2⁵²⁴²⁸⁸⁰ unique books; around 1.4×10¹⁵⁷⁸²⁶⁴ books.
This section aims to simplify and explain how this software works mathematically, in the hopes of providing some insight to others.
Each book in the library contains 512 pages, with each page containing 32 lines, and each line containing 64 characters. We have 64 possible characters, so each character can be represented by 6 bits. In total, each book can be represented by
The library is not truly random. In fact, using randomness would make it more difficult to guarantee that every possible book exists in the library. Instead, the aim is to create something that looks random enough, i.e. if you start at book 0 and read in sequence, everything will look like gibberish, but where we can easily figure out where a book of interest lies within the library. The way this is achieved is by picking two random values: the starting book,
This way, if
where
but computing this directly is very slow (similar computations are used to create time-locked puzzles [1]!). Instead, we can take advantage of the algorithm developed by Hurchalla [2], taking advantage of the fact that our base is a power of 2 to compute this in only a few multiplications. Now it is possible to quickly find any
[1] R. L. Rivest, A. Shamir, D. A. Wagner, Time-lock puzzles and timed-release crypto, dspace.mit.edu
[2] J. Hurchalla, An improved integer modular multiplicative inverse (modulo 2^w), arxiv.org