gchq/CyberChef · error · OperationError
The key must consist only of letters in the English alphabet
Error message
The key must consist only of letters in the English alphabet
What it means
The Bifid cipher builds a 5x5 Polybius square from a keyword (with J merged into I). After uppercasing and the J->I replacement, the keyword string must consist only of A-Z letters. This OperationError fires when non-alphabetic characters survive that preprocessing and at least one unique letter remains, because non-letter glyphs cannot be placed in the Polybius grid.
Source
Thrown at src/core/operations/BifidCipherEncode.mjs:57
* @param {Object[]} args
* @returns {string}
*
* @throws {OperationError} if key is invalid
*/
run(input, args) {
const keywordStr = args[0].toUpperCase().replace("J", "I"),
keyword = keywordStr.split("").unique(),
alpha = "ABCDEFGHIKLMNOPQRSTUVWXYZ",
xCo = [],
yCo = [],
structure = [];
let output = "",
count = 0;
if (!/^[A-Z]+$/.test(keywordStr) && keyword.length > 0)
throw new OperationError("The key must consist only of letters in the English alphabet");
const polybius = genPolybiusSquare(keywordStr);
input.replace("J", "I").split("").forEach(letter => {
const alpInd = alpha.split("").indexOf(letter.toLocaleUpperCase()) >= 0;
let polInd;
if (alpInd) {
for (let i = 0; i < 5; i++) {
polInd = polybius[i].indexOf(letter.toLocaleUpperCase());
if (polInd >= 0) {
xCo.push(polInd);
yCo.push(i);
}
}
if (alpha.split("").indexOf(letter) >= 0) {
structure.push(true);View on GitHub (pinned to 4290ea7539)
Solutions
- Sanitize the key before invoking the operation: strip everything except A-Z/a-z (key.replace(/[^A-Za-z]/g, '')).
- Leave the key empty if you want the default alphabet square (the check only fires when unique-letter count > 0).
- Validate the key in your UI/config layer with /^[A-Za-z]+$/ before passing it as args[0].
Example fix
// before const args = ['my secret 123']; // after const args = ['mysecret'];
Defensive patterns
Strategy: validation
Validate before calling
const key = (args[0] || '').toUpperCase().replace(/J/g, 'I');
if (key.length > 0 && !/^[A-Z]+$/.test(key)) {
throw new Error('Bifid key must be A-Z only');
} Type guard
function isBifidKey(k) {
const s = String(k).toUpperCase().replace(/J/g, 'I');
return s.length === 0 || /^[A-Z]+$/.test(s);
} Try / catch
try { bifidEncode.run(input, [key]); }
catch (e) { if (/letters in the English alphabet/.test(e.message)) { /* sanitize key */ } else throw e; } Prevention
- Validate the key with /^[A-Za-z]+$/ in the UI before adding the operation to the recipe.
- Strip non-letter characters from user input with replace(/[^A-Za-z]/g, '').
- Treat an empty key as intentional rather than an error.
When it happens
Trigger: Calling BifidCipherEncode.run with an args[0] key that contains digits, punctuation, whitespace, or accented/non-Latin characters while also containing at least one letter (so keyword.length > 0 and /^[A-Z]+$/ fails).
Common situations: User pastes a passphrase containing spaces, numbers, or symbols; an IME or autocorrect inserts non-ASCII characters; a config/UI forwards an unvalidated key string.
Related errors
- Invalid Base64 alphabet length (${alphabet.length}): ${alpha
- Error: Base64 alphabet should be 64 characters long, or 65 w
- Letter ${letter} is not included in LS47
- Invalid ciphertext length: ${originalLength} bytes. Must be
- No padding requested in ${mode} mode but input is not a 16-b
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/e6c4b10a5af130fd.
Report an issue: GitHub.