subst

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: 3 Imported by: 0

Documentation

Overview

Package subst solves monoalphabetic substitution ciphers by hill-climbing over the 26! key space, scored by an embedded English n-gram model. It seeds from a frequency match and refines with random key-swaps under random restarts — the standard approach for this class of cipher.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Key

type Key [26]byte

Key is a substitution key: Key[c] is the plaintext letter index (0..25) for ciphertext letter index c. It is always a permutation of 0..25.

func Solve

func Solve(ct []byte, m *lang.Model, r *rand.Rand, opt Options) (Key, []byte, float64)

Solve recovers the most English-like substitution key for ct using model m and randomness r. It returns the best key, its decryption, and its score.

func (Key) Decrypt

func (k Key) Decrypt(ct []byte) []byte

Decrypt applies the key, preserving case and passing non-letters through.

type Options

type Options struct {
	Restarts int // independent hill-climbs (default 25)
	MaxFails int // consecutive non-improving swaps before a restart ends (default 1500)
}

Options tune the search. Zero values get sensible defaults.

Jump to

Keyboard shortcuts

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