lang

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package lang holds a small embedded English language model used to score candidate plaintexts during cipher solving (e.g. the monoalphabetic substitution hill-climb). The model is built at init from an embedded public-domain English corpus (corpus.txt) — no network, no external data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clean

func Clean(s []byte) []int

Clean returns the A..Z letter indices of s (case-folded, non-letters dropped).

func FreqOrder

func FreqOrder() []int

FreqOrder returns the 26 letter indices ordered from most to least frequent in the corpus. Used to seed a frequency-matched starting key.

func LetterIndex

func LetterIndex(b byte) int

Letters maps a byte to a 0..25 letter index, or -1 for non-letters (case-folded).

Types

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model is an n-gram log-probability scorer over the 26-letter alphabet.

func EnglishTrigram

func EnglishTrigram() *Model

EnglishTrigram returns the cached trigram model.

func NewModel

func NewModel(n int) *Model

NewModel builds an n-gram model from the embedded corpus.

func (*Model) Score

func (m *Model) Score(text []byte) float64

Score sums the n-gram log-probabilities of text (case-folded, letters only). Higher is more English-like. Texts shorter than n score 0.

Jump to

Keyboard shortcuts

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