Skip to content
unusualeventPublic

About

A Go library implementing the Library of Babel algorithm using boardgame compression.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

15 Commits

Folders and files

Repository files navigation

ouija

A Go library implementing the Library of Babel algorithm for arbitrary binary data.

Every possible page of bytes exists in the library. Given any sequence of bytes, ouija can find an address for it; given any address, ouija returns the page stored there. The mapping is deterministic and reversible.

Install

go get code.dwrz.net/ouija

Usage

package main

import (
	"fmt"

	"code.dwrz.net/ouija"
)

func main() {
	// Find a page containing some data.
	data := []byte{0x48, 0x65, 0x6c, 0x6c, 0x6f}
	addr, err := ouija.Search(data)
	if err != nil {
		panic(err)
	}
	fmt.Println("Address:", addr)

	// Retrieve the page.
	page, err := ouija.GetPage(addr)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Page length: %d\n", len(page))

	// The data appears somewhere on the page.
	// ...
}

text subpackage

The text subpackage provides a convenience layer for source code. It compresses text with boardgame before storing it in the library.

package main

import (
	"fmt"

	"code.dwrz.net/ouija/text"
)

func main() {
	src := []byte("package main\n\nfunc main() {\n\tfmt.Println(1 + 2)\n}\n")

	addr, err := text.Search(src)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Address: %s\n", addr)

	// Only the address is needed to recover the original text.
	recovered, err := text.Recover(addr)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Recovered: %s\n", recovered)
}

Address Format

HexAddr:Wall:Shelf:Volume:Page
Field Range Description
HexAddr base-36 string Encodes the page content
Wall 0–3 Wall in the hexagonal room
Shelf 0–4 Shelf on the wall
Volume 00–31 Book on the shelf
Page 000–409 Page in the book

Self-Referential Example

The example/ directory contains a program that computes the Library of Babel addresses of ouija.go itself, using the text subpackage to compress source with boardgame before searching. The addresses alone are sufficient to recover the original source — they are kept in example/data.txt. A portable pre-commit hook and CI step ensure these addresses stay current whenever the source changes.

To enable the pre-commit hook:

git config core.hooksPath hooks

See example/README.md for details.

Algorithm

See docs/algorithm.md for a detailed description.

License

See LICENSE.

About

A Go library implementing the Library of Babel algorithm using boardgame compression.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages