Documentation
¶
Overview ¶
Package entropy implements password entropy calculation.
This file provides pattern-aware entropy calculation. Instead of applying a post-hoc multiplicative reduction to the pool-size estimate, it uses a segment-based model: each detected pattern segment contributes only its intrinsic entropy — the bits needed to describe the pattern choice to an attacker who already knows the pattern class — while uncovered characters contribute the standard character-pool entropy.
Package entropy implements password entropy calculation.
It estimates the entropy of a password in bits based on the character sets used and the password length, giving a measure of how unpredictable the password is.
Entropy is calculated as:
bits = runeCount × log2(poolSize)
where poolSize is the total number of possible characters based on which character sets (lowercase, uppercase, digits, symbols) are present.
Package entropy implements password entropy calculation.
This file provides Markov-chain analysis for character transition probabilities to estimate entropy more accurately by considering how characters typically follow each other in real passwords.
Package entropy implements password entropy calculation.
This file provides mode selection logic for different entropy calculation methods.
Index ¶
- Constants
- func Calculate(password string) float64
- func CalculateAdvanced(password string, patternIssues []issue.Issue) float64
- func CalculatePatternAware(password string, patternIssues []issue.Issue) float64
- func CalculateWithMode(password, mode string, patternIssues []issue.Issue) float64
- type CharsetInfo
- type Mode
Constants ¶
const ( PoolLower = 26 PoolUpper = 26 PoolDigit = 10 PoolSymbol = 32 )
Character pool sizes for each set.
Variables ¶
This section is empty.
Functions ¶
func Calculate ¶
Calculate estimates the entropy of a password in bits.
Length is measured in Unicode code points (runes), not bytes, so multi-byte characters are counted correctly.
func CalculateAdvanced ¶ added in v1.3.0
CalculateAdvanced calculates entropy using a segment-based model.
The password is partitioned into two kinds of regions:
Pattern segments (identified by the Pattern field of each issue.Issue): contribute only the intrinsic entropy of their pattern class (see intrinsicPatternEntropy).
Free characters (not covered by any detected pattern): contribute the standard character-pool entropy (bits = count × log2(poolSize)).
Repeated-block patterns are counted once regardless of how many times the block repeats in the password; all repetitions are marked as covered but add no additional entropy.
Issues whose Pattern field is empty are silently ignored (e.g. issues from rule or dictionary checkers that are unrelated to structural patterns).
func CalculatePatternAware ¶ added in v1.3.0
CalculatePatternAware calculates entropy using pattern-aware adjustments plus Markov-chain analysis for character transition probabilities.
Types ¶
type CharsetInfo ¶
type CharsetInfo struct {
HasLower bool // at least one lowercase letter
HasUpper bool // at least one uppercase letter
HasDigit bool // at least one digit
HasSymbol bool // at least one symbol / punctuation
}
CharsetInfo holds the results of a single-pass character set analysis.
func AnalyzeCharsets ¶
func AnalyzeCharsets(password string) (info CharsetInfo, runeCount int)
AnalyzeCharsets performs a single pass over the password to determine which character set types are present and counts the number of runes. Uses the unicode package for correct handling of non-ASCII letters and digits.
func (CharsetInfo) PoolSize ¶
func (c CharsetInfo) PoolSize() int
PoolSize returns the total number of possible characters based on which sets are present.
func (CharsetInfo) SetCount ¶
func (c CharsetInfo) SetCount() int
SetCount returns how many of the four character set types are present.