TheAlgorithms/Go · error
ErrNoTextToEncrypt
ErrNoTextToEncrypt
Error message
%w: cannot encrypt a text, %q, ending with the placeholder char %q
What it means
Encrypt pads text with a placeholder rune; input that already ends with that placeholder would make correct unpadding ambiguous on decrypt, so Encrypt refuses it, wrapping ErrNoTextToEncrypt with the text and placeholder shown.
Source
Thrown at cipher/transposition/transposition.go:64
if wordSet[i] == subString {
return i
}
}
return 0
}
func Encrypt(text []rune, keyWord string) ([]rune, error) {
key := getKey(keyWord)
keyLength := len(key)
textLength := len(text)
if keyLength <= 0 {
return nil, ErrKeyMissing
}
if textLength <= 0 {
return nil, ErrNoTextToEncrypt
}
if text[len(text)-1] == placeholder {
return nil, fmt.Errorf("%w: cannot encrypt a text, %q, ending with the placeholder char %q", ErrNoTextToEncrypt, text, placeholder)
}
n := textLength % keyLength
for i := 0; i < keyLength-n; i++ {
text = append(text, placeholder)
}
textLength = len(text)
var result []rune
for i := 0; i < textLength; i += keyLength {
transposition := make([]rune, keyLength)
for j := 0; j < keyLength; j++ {
transposition[key[j]-1] = text[i+j]
}
result = append(result, transposition...)
}
return result, nil
}
View on GitHub (pinned to 5ba447ec5f)
Solutions
- Strip or escape the placeholder character from the plaintext before encrypting
- Choose a placeholder guaranteed absent from your plaintext alphabet
- Detect via errors.Is(err, ErrNoTextToEncrypt) and sanitize then retry
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at cipher/transposition/transposition.go:64 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/e2125b418c23b132.
Report an issue: GitHub.