Toktok
Typo/error resilient, human-readable token generator
Install / Use
/learn @muesli/ToktokREADME
toktok
A human-friendly token generator
Creates tokens which avoid characters that can be easily misinterpreted, like '1' and 'I' or '8' and 'B', as well as repeated characters within the token. It also compares newly generated tokens to all previously generated ones and guarantees a safety distance between the tokens, so they become resilient to typos or other human entry errors.
Installation
Make sure you have a working Go environment (Go 1.11 or higher is required). See the install instructions.
To install toktok, simply run:
go get github.com/muesli/toktok
Compiling toktok is easy, simply run:
git clone https://github.com/muesli/toktok.git
cd toktok
go build && go test -v
Example
package main
import (
"fmt"
"github.com/muesli/toktok"
)
func main() {
// Generate a new token bucket.
// Each generated token will be 8 characters long.
bucket, _ := toktok.NewBucket(8)
// Generate a bunch of tokens with a safety distance of 4.
// Distance is calculated by insertion cost (1), deletion cost (1) and
// substitution cost (2).
for i := 0; i < 9; i++ {
token, _ := bucket.NewToken(4)
fmt.Printf("Generated Token %d: %s\n", i, token)
}
// One more token that we will tamper with.
token, _ := bucket.NewToken(4)
fmt.Printf("Generated Token 9: %s\n", token)
token = "_" + token[1:7] + "_"
// Find the closest match for the faulty token.
match, distance := bucket.Resolve(token)
fmt.Printf("Best match for '%s' is token '%s' with distance %d\n", token, match, distance)
}
Result
Generated Token 0: J3KPC9YF
Generated Token 1: PXTWDC9P
Generated Token 2: WNANK4FU
...
Generated Token 9: Y3NCDFWN
Best match for '_3NCDFW_' is token 'Y3NCDFWN' with distance 4
Feedback
Got some feedback or suggestions? Please open an issue or drop me a note!
Related Skills
node-connect
351.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
351.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
351.8kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
