Documentation
¶
Overview ¶
Package analyze provides functionality for cryptanalysis of classical ciphers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnalyzeFile ¶
func AnalyzeFile[T []CaesarResult | []VigenereResult](analyzer Analyzer[T], inputFilepath string) (T, error)
AnalyzeFile reads a file and analyzes its contents using the provided analyzer.
It reads up to 16KB of data from the file and returns the analysis results.
Types ¶
type Analyzer ¶
type Analyzer[T []CaesarResult | []VigenereResult] interface { /* AnalyzeBuffer analyzes the given byte buffer and returns a slice of results containing the detected key(s) and their corresponding chi-squared scores. */ AnalyzeBuffer(buffer []byte) (T, error) }
Analyzer defines the interface for cipher analysis implementations.
type CaesarAnalyzer ¶
type CaesarAnalyzer struct {
// contains filtered or unexported fields
}
CaesarAnalyzer performs statistical analysis to crack Caesar cipher encrypted text.
It uses chi-squared frequency analysis to determine the most likely key.
func NewCaesarAnalyzer ¶
func NewCaesarAnalyzer() *CaesarAnalyzer
NewCaesarAnalyzer creates a new CaesarAnalyzer instance.
func (*CaesarAnalyzer) AnalyzeBuffer ¶
func (analyzer *CaesarAnalyzer) AnalyzeBuffer(buffer []byte) ([]CaesarResult, error)
AnalyzeBuffer analyzes the given buffer to find the most likely Caesar cipher key.
It returns a slice of CaesarResult sorted by chi-squared score (best match first).
type CaesarResult ¶
CaesarResult holds the analysis result for Caesar cipher, containing the detected key and its chi-squared score.
type VigenereAnalyzer ¶
type VigenereAnalyzer struct {
// contains filtered or unexported fields
}
VigenereAnalyzer performs statistical analysis to crack Vigenère cipher encrypted text.
It uses n-gram frequency analysis and Kasiski examination to determine the key length, then applies Caesar cipher analysis to each character position to recover the key.
func NewVigenereAnalyzer ¶
func NewVigenereAnalyzer(maxNgramLength int) (*VigenereAnalyzer, error)
NewVigenereAnalyzer creates a new VigenereAnalyzer instance.
The maxNgramLength parameter specifies the maximum n-gram length to use for analysis. It has to be positive.
func (*VigenereAnalyzer) AnalyzeBuffer ¶
func (analyzer *VigenereAnalyzer) AnalyzeBuffer(buffer []byte) ([]VigenereResult, error)
AnalyzeBuffer analyzes the given buffer to find the most likely Vigenère cipher key.
It returns a slice of VigenereResult sorted by chi-squared score (best match first).
The maximum number of results returned is 10.
type VigenereResult ¶
VigenereResult holds the analysis result for Vigenère cipher, containing the detected key and its chi-squared score.