• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

cakenggt/Library-Of-Pybel: Library of Babel clone in Python

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

cakenggt/Library-Of-Pybel

开源软件地址(OpenSource Url):

https://github.com/cakenggt/Library-Of-Pybel

开源编程语言(OpenSource Language):

Python 100.0%

开源软件介绍(OpenSource Introduction):

Library Of Pybel

About

This is an open source python implementation of the Library of Babel.

Functionality

Javascript Implementation

The Javascript implementation of the Library of Babel can be found here. The text and addresses generated will not be the same between the Python implementation and this one. The source code for this JS implementation is hosted in the gh-pages branch. There is a search box and an address selector.

Python Implementation

Note: all numbers are started at 0, not 1. To find the first page of a book, look for page 0

Address format: Hex_Value:Wall:Shelf:Volume:Page

Examples:

  • 98756SDH987S:2:3:14:345
  • HELLO:0:0:0:0

Run the file from the command line with an action argument. The following arguments are supported:

  • --checkout <addr> Checks out a page of a book. Also displays the page's title.
  • --fcheckout <file> Does exactly the checkout does, but with address in the file.
  • --search <'text'> Does 3 searches for the text you input.
    • Page contains: Finds a page which contains the text.
    • Page only contains: Finds a page which only contains that text and nothing else.
    • Title match: Finds a title which is exactly this string. Mind the quotemarks.For a title match, it will only match the first 25 characters. Addresses returned for title matches will need to have a page number added to the tail end, since they lack this.
  • --fsearch <file> Does exactly the search does, but with text in the file.
  • --file <file> Dump search result into the file.
  • --help Prints help message.

Explanation

What was needed for this project was a way to generate seemingly random pages in a near-infinite address space which could also be searched for specific strings.

I realized not early on that what I needed was not a reversible RNG, but in fact an encoding scheme to cleverly encode the page's text in the address of the book. Paired with a seeded RNG for shorter pages, I could reliably generate random pages, but also encode specific text into the page to be generated.

To understand the encoding, you must think of the hex address of the book as a base-36 number and the text of the book as a base-29 number (26 letters plus space, comma, and period). The wall, shelf, volume, and page can be thought of as a base-10 number independent of the hex address. This base-10 number will be referred to as the location.

Specifically, when text is searched for, that text is padded with a random amount of characters on it's front and back side, or in the case of the Page only contains, it's padded with spaces on it's back side. Then, a random number in the range of each location value is calculated.

The page text is then converted from a string to a number. The location number is multiplied by a very large number and is then added to the page text number. Then the new page text number is converted into base-36, and that is the address.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap