trekhleb/javascript-algorithms · error · Error
The message and key string can only contain letters
Error message
The message and key string can only contain letters
What it means
Error "The message and key string can only contain letters" thrown in trekhleb/javascript-algorithms.
Source
Thrown at src/algorithms/cryptography/hill-cipher/hillCipher.js:63
export function hillCipherEncrypt(message, keyString) {
// The keyString and message can only contain letters.
const onlyLettersRegExp = /^[a-zA-Z]+$/;
if (!onlyLettersRegExp.test(message) || !onlyLettersRegExp.test(keyString)) {
throw new Error('The message and key string can only contain letters');
}}View on GitHub (pinned to 85293e3e2b)
Solutions
- Strip or reject any non-letter characters from message and keyString before encrypting.
- Validate both inputs against /^[a-zA-Z]+$/ on the caller side and surface a validation error to the user.
- Normalize input by uppercasing and removing spaces and punctuation if the application allows it.
When it happens
Trigger: hillCipherEncrypt is called with a message or keyString that fails the /^[a-zA-Z]+$/ check — containing digits, spaces, punctuation, non-letter symbols, or being an empty string.
Common situations: Passing plaintext with spaces or punctuation, or a key containing numbers, to the Hill cipher, which only supports letters.
AI-assisted analysis of trekhleb/javascript-algorithms@85293e3e2b (2026-08-24).
Data as JSON: /api/errors/a73323cf809a6091.
Report an issue: GitHub.