TheAlgorithms/Go · error
%c does not exist in characters
Error message
%c does not exist in characters
What it means
decipher resolves the row/column via strings.IndexRune in the cipher's character alphabet; a rune not in 'characters' (e.g. text not produced by this cipher) yields -1 and triggers this error naming the character.
Source
Thrown at cipher/polybius/polybius.go:95
func (p *Polybius) encipher(char rune) (string, error) {
index := strings.IndexRune(p.key, char)
if index < 0 {
return "", fmt.Errorf("%q does not exist in keys", char)
}
row := index / p.size
col := index % p.size
chars := []rune(p.characters)
return string([]rune{chars[row], chars[col]}), nil
}
func (p *Polybius) decipher(chars []rune) (string, error) {
if len(chars) != 2 {
return "", fmt.Errorf("the size of \"chars\" must be even")
}
row := strings.IndexRune(p.characters, chars[0])
if row < 0 {
return "", fmt.Errorf("%c does not exist in characters", chars[0])
}
col := strings.IndexRune(p.characters, chars[1])
if col < 0 {
return "", fmt.Errorf("%c does not exist in characters", chars[1])
}
return string(p.key[row*p.size+col]), nil
}
View on GitHub (pinned to 5ba447ec5f)
Solutions
- Validate ciphertext characters against the cipher alphabet before decrypting
- Ensure encrypt/decrypt use the same size and characters configuration
- Strip or reject foreign characters in the input
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at cipher/polybius/polybius.go:95 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of TheAlgorithms/Go@5ba447ec5f (2026-09-02).
Data as JSON: /api/errors/f66f5c33cecdd7c9.
Report an issue: GitHub.