Documentation
¶
Overview ¶
Package brute is the toolkit's generic keyspace brute-force engine: pluggable Cipher, KeySpace, and Scorer interfaces driving an ordered, resumable sweep that keeps the top-scoring candidates. It ships the classical building blocks (XOR, Caesar) and scorers (printable, English frequency, known-plaintext crib), plus the smart single-byte and repeating-key XOR solvers that decompose the otherwise-astronomical repeating-key keyspace into per-column single-byte sweeps.
Index ¶
- type ByteKeySpace
- type Caesar
- type Candidate
- func Run(ctx context.Context, c Cipher, ks KeySpace, sc Scorer, ct []byte, opt Options) []Candidate
- func SolveCaesar(ct []byte, sc Scorer) Candidate
- func SolveRepeatingXOR(ct []byte, keyLen int, sc Scorer) Candidate
- func SolveSingleByteXOR(ct []byte, sc Scorer) Candidate
- func SolveVigenere(ct []byte, keyLen int, sc Scorer) Candidate
- type Cipher
- type Crib
- type English
- type KeySpace
- type Options
- type Printable
- type Scorer
- type Vigenere
- type XOR
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ByteKeySpace ¶
type ByteKeySpace struct {
Len int
// contains filtered or unexported fields
}
ByteKeySpace enumerates all keys of a fixed byte length as a big-endian odometer. Practical for 1–3 bytes; wider keys should use the smart per-column solvers below.
func (*ByteKeySpace) Next ¶
func (k *ByteKeySpace) Next() ([]byte, bool)
func (*ByteKeySpace) Position ¶
func (k *ByteKeySpace) Position() uint64
func (*ByteKeySpace) Seek ¶
func (k *ByteKeySpace) Seek(p uint64)
func (*ByteKeySpace) Size ¶
func (k *ByteKeySpace) Size() uint64
type Candidate ¶
Candidate is one scored decryption.
func Run ¶
Run sweeps ks, decrypting ct with c and scoring with sc, returning the TopN highest-scoring candidates in descending score order. It honors ctx cancellation between keys.
func SolveCaesar ¶
SolveCaesar finds the single-byte additive (Caesar) shift best explaining ct.
func SolveRepeatingXOR ¶
SolveRepeatingXOR recovers a repeating-key XOR key of the given length by solving each key column independently as a single-byte XOR — the standard decomposition that turns 256^keyLen into keyLen×256.
func SolveSingleByteXOR ¶
SolveSingleByteXOR finds the single-byte XOR key best explaining ct.
type Crib ¶
Crib rewards plaintexts containing a known substring (known-plaintext). It composes a base scorer with a large bonus when the crib appears.
type English ¶
type English struct{}
English scores a plaintext by average per-byte log-likelihood under an English letter-frequency model (case-folded). Non-letters that are printable get a small floor; non-printable bytes are penalized heavily, so gibberish keys score far below readable text.
type KeySpace ¶
type KeySpace interface {
Next() (key []byte, ok bool)
Position() uint64
Seek(pos uint64)
Size() uint64 // 0 means unknown/unbounded
}
KeySpace is an ordered, seekable enumerator over candidate keys. Ordered + seekable is what makes a sweep resumable from a checkpointed position.
type Options ¶
type Options struct {
TopN int // keep this many best candidates (default 5)
OnTick func(pos, size uint64) // optional progress callback
TickEach uint64 // call OnTick every N keys (default 65536)
}
Options configure a Run.
type Printable ¶
type Printable struct{}
Printable scores the fraction of bytes that are printable ASCII or common whitespace. Cheap and language-agnostic — a good first filter.