iching

package module
v0.0.0-...-309af5a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2022 License: MIT Imports: 1 Imported by: 0

README

A new way to encode binary numbers

I Ching or "Classic of Change" is a Chinese book about telling the future or something. It doesn't matter.

What matters is that I Ching defines a set of 64 "figures", called hexagrams, each consisting of 6 stacked horizontal lines, where each line is either a solid, unbroken line (Yang) or a line with a single gap (Yin).

Each hexagram can therefore be easily used to encode a number up to 6bits of entropy, this library implements a function (Itoiching) to convert an arbitrary 64bit unsigned integer into its I Ching representation and a function (Ichingtoi) to do the reverse.

Conventions

Each I Ching character represents a 6 bit value, strings are ordered with the most significant 6 bits of the number first. Withing a I Ching character the top line represents the most significant bit of the sextet. The unbroken line (Yang) corresponds to 0, the broken line (Yin) corresponds to 1. We do not use the King Wen sequence.

Example

  iching.Itoiching(23) → ䷢

Example programs

This library comes with two example programs (available under the cmd directory). Ichingtest takes a number as argument on the command line and converts it to its representation in decimal, octal and I Ching. The other program is ichingdump and it's similar to hexdump (or od) but using I Ching encoding for all numbers.

Crystal clear

Documentation

Overview

I Ching or "Classic of Change" is a Chinese book about telling the future or something. It doesn't matter.

What matters is that I Ching defines a set of 64 "figures", called hexagrams, each consisting of 6 stacked horizontal lines, where each line is either a solid, unbroken line (Yang) or a line with a single gap (Yin).

Each hexagram can therefore be easily used to encode a number up to 6bits of entropy, this library implements a function (`Itoiching`) to convert an arbitrary 64bit unsigned integer into its I Ching representation and a function (`Ichingtoi`) to do the reverse.

Each I Ching character represents a 6 bit value, strings are ordered with the most significant 6 bits of the number first. Withing a I Ching character the top line represents the most significant bit of the sextet. The unbroken line (Yand) corresponds to 0, the broken line corresponds to 1. We do not use the King Wen sequence.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ichingtoi

func Ichingtoi(in string) (uint64, error)

Parses a number encoded as I Ching characters

func Itoiching

func Itoiching(in uint64) string

Converts in to its I Ching encoding

func QianPad

func QianPad(in string, sz int) string

Pads a string with Qián characters (the character that represents 0 in our encoding) up to a total sz runes

func SpacePad

func SpacePad(in string, sz int) string

Pads a string with space characters up to a total of sz runes

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL