{"record":{"id":"a73323cf809a6091","repo":"trekhleb/javascript-algorithms","slug":"the-message-and-key-string-can-only-contain-letter","errorCode":null,"errorMessage":"The message and key string can only contain letters","messagePattern":"The message and key string can only contain letters","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/algorithms/cryptography/hill-cipher/hillCipher.js","lineNumber":63,"sourceCode":"export function hillCipherEncrypt(message, keyString) {\n  // The keyString and message can only contain letters.\n  const onlyLettersRegExp = /^[a-zA-Z]+$/;\n  if (!onlyLettersRegExp.test(message) || !onlyLettersRegExp.test(keyString)) {\n    throw new Error('The message and key string can only contain letters');\n  }}","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/src/algorithms/cryptography/hill-cipher/hillCipher.js#L45-L81","documentation":"Error \"The message and key string can only contain letters\" thrown in trekhleb/javascript-algorithms.","triggerScenarios":"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.","commonSituations":"Passing plaintext with spaces or punctuation, or a key containing numbers, to the Hill cipher, which only supports letters.","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."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"85293e3e2b88f4d2ce330d956b139cf628aa1e82","analyzedAt":"2026-08-24T05:59:10.417Z","schemaVersion":2},"datasetVersion":"2026-08-24T07:17:09.176Z"}