In the most simple terms:
Crucially, the mathematical function is reversible meaning that we can instead give it the contents of a page and determine the page number that it appears on.
For a more detailed explanation and to view the source code, please see the GitHub repository.
No, that would be cheating! It is easy to assume that this website just takes whatever text you search for, inserts it into a random page, and saves that page on disk so that you can find it again at a later date. Similarly with pages of gibberish, what’s to say they aren’t just generated randomly when you request them and saved for later?
Building a Library of Babel this way would require unobtainable amounts of storage. A single page (content only) takes up 3200 bytes, with a single byte per ASCII character. 3200 bytes multiplied by 293200 unique pages gives us a total size of 1.509×104671 TB — an infeasible amount of data to store, to say the least.
Thus to build a virtual Library of Babel, we have to use a method that doesn’t require any storage. Pages are generated on the fly based on their page number, and the same page number will continue to generate the same page forever, unless the algorithm is changed.
If you haven’t already read the story then start there! The website libraryofbabel.info also contains lots of supplemental information and theory, as well as another implementation of the library itself.